//需在场景中创建两个物体做为检测对象
var target1: Transform;
var target2: Transform;
function Update () {
if (Input.GetMouseButton(0)) {
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if (Physics.Raycast(ray, hit)) {
if (hit.transform == target1) {
target1.transform.Rotate(0,5,0);
} else if (hit.transform == target2) {
print("Hit target 2");
}
} else {
print("Hit nothing");
}
}
}
我只改了一个物体移动,剩下的自己改 |