Ray射線使用。

<img src="https://img-blog.csdn.net/20150818164450667?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />void Update () {
		if (Input.touchCount>0) {
			Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			RaycastHit hitInfo;
			if(Physics.Raycast(ray,out hitInfo))
			{
				Debug.DrawLine(ray.origin,hitInfo.point);
				GameObject obj = hitInfo.collider.gameObject;
				Debug.Log ("Click object name is " + obj.name);
				obj.GetComponent<Rigidbody>().AddForce(new Vector3(Random.Range(1,100000),Random.Range(1,100000),Random.Range(1,100000)));
			}
		}
	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章