Place a mark on the intersection of the mouse and the scene, and disappear after 1s:
Create a new empty Gameobject, named Moushhittest, and add the following script:
Using Unityengine;
Using System.Collections;
public class Mousehit:monobehaviour {
Public Gameobject M_moushhitmarkprefab;
Use this for initialization
void Start () {
}
Update is called once per frame
void Update () {
if (Input.getmousebuttondown (0)) {//left button down
Ray Camray = Camera.main.ScreenPointToRay (input.mouseposition);
Raycasthit Hitinfo;
float camraylength = 100f;
BOOL Ishit = Physics.raycast (camray,out hitinfo,camraylength);
if (ishit) {
Debug.Log (Hitinfo.point);
Object instance=instantiate (M_moushhitmarkprefab, Hitinfo.point, quaternion.identity);
Instance.name= "Hitmark";
About Startcoroutine and yield:http://stackoverflow.com/questions/12932306/ How-does-startcoroutine-yield-return-pattern-really-work-in-unity
Startcoroutine (Delaydestroy (instance));
}
}
}
IEnumerator Delaydestroy (Object instance) {
Yield return new waitforseconds (1.0f);
Destroy (instance);
}
}
Unity, mouse and scene intersection