SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ShotBehavior : MonoBehaviour
  5. {
  6.  
  7.     public Vector3 m_target;
  8.     public GameObject collisionExplosion;
  9.     public float speed;
  10.  
  11.  
  12.     // Update is called once per frame
  13.     void Update()
  14.     {
  15.         // transform.position += transform.forward * Time.deltaTime * 300f;// The step size is equal to speed times frame time.
  16.         float step = speed * Time.deltaTime;
  17.  
  18.         if (m_target != null)
  19.         {
  20.             if (transform.position == m_target)
  21.             {
  22.                 explode();
  23.                 return;
  24.             }
  25.             transform.position = Vector3.MoveTowards(transform.position, m_target, step);
  26.         }
  27.  
  28.     }
  29.  
  30.     public void setTarget(Vector3 target)
  31.     {
  32.         m_target = target;
  33.     }
  34.  
  35.     void explode()
  36.     {
  37.         if (collisionExplosion  != null) {
  38.             GameObject explosion = (GameObject)Instantiate(
  39.                 collisionExplosion, transform.position, transform.rotation);
  40.             Destroy(gameObject);
  41.             Destroy(explosion, 1f);
  42.         }
  43.  
  44.  
  45.     }
  46.  
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top