Findwithtag find tag, find lookup name, 2 functions Find game Object
Gameobject.findwithtag
Gameobject.find
The following example moves the camera while tracking the movement of the ball
#pragma strict//code:[email protected]//date:2014-08-13import system;var translate_object:rigidbody;var li:int=20; var floor_y:int;var mycamera:gameobject;var camera_bh:float;function Start () {var floor:gameobject= Gameobject.findwithtag ("Myfloor"); Mycamera=gameobject.find ("Ball_camera"); floor_y=-floor.transform.position.y+ 5;camera_bh=0.01;} function Fixedupdate () { if (translate_object!=null) { if (translate_object.rigidbody.transform.position.y <floor_y) { translate_object.rigidbody.AddForce (0,li,0); } } if (mycamera.transform.rotation.x>-0.10 | | mycamera.transform.rotation.x<-0.12) { camera_bh=-camera_bh; } mycamera.transform.Rotate (camera_bh,0,0); }
mai good AI Paradise Blog All content is original, if reproduced please indicate source http://blog.csdn.net/myhaspl/
The following layouts:
See the results:
Http://mygame.myhaspl.com/test3/test3.html