NeedleRotateCtrl |
public class NeedleRotateCtrl : MonoBehaviour { public Transform gun; public Transform pivot; float prevAngle; // Use this for initialization void Start () { prevAngle = gun.transform.rotation.eulerAngles.z; } // Update is called once per frame void Update () { float currentAngle = gun.transform.rotation.eulerAngles.z; float deltaAngle = currentAngle - prevAngle; if(deltaAngle != 0) { transform.RotateAround(pivot.position,Vector3.forward,deltaAngle); } prevAngle = currentAngle; } } |
Time, rigidbody.AddExplosionForce |
float startTime; float bomLiveTime = 5.0f; float bomRadius = 15.0f; float bomForce = 1000.0f;
// Use this for initialization void Start () { startTime = Time.time; } // Update is called once per frame void Update () { if((Time.time - startTime) > bomLiveTime) { Bom(); } } void OnCollisionEnter(Collision Col) { Bom (); } void Bom() { Collider[] collider = Physics.OverlapSphere(transform.position,bomRadius); foreach(Collider col in collider) { if(!col.gameObject.Equals(gameObject) && col.rigidbody != null) { rigidbody.AddExplosionForce
(bomForce,transform.position,bomRadius,5.0f); } } Destroy(gameObject); } |
|
외부 스크립트 사용하기 |
public RocketShoot rocketshoot;
rocketshoot = GameObject.Find("RocketShoot").GetComponent<RocketShoot>();
rocketshoot.fire();
RocketShoot ---> 오브젝트 이름 RocketShoot ---> 스크립트 이름 |
|
transform.FindChild("door").SendMessage("DoorCheck"); //transform -> 경로명을 포함한다. |
|
|
|