Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class Bullet : MonoBehaviour
  2. {
  3. public GameObject Gun ;
  4. public Vector3 direction ;
  5.  
  6. public void Awake()
  7. {
  8. // You can't use Gun yet
  9. }
  10.  
  11. public void Start()
  12. {
  13. if( Gun != null )
  14. Debug.Log("I've been instiated by " + Gun.name ) ;
  15. }
  16.  
  17. public void Update()
  18. {
  19. transform.Translate( direction ) ;
  20. }
  21. }
  22.  
  23. public class Gun : MonoBehaviour
  24. {
  25. public void Shoot()
  26. {
  27. GameObject instance = Instantiate( bulletPrefab ) ;
  28. Bullet bullet = instance.GetComponent<Bullet>();
  29. if( bullet != null )
  30. {
  31. bullet.Gun = gameObject;
  32. bullet.Direction = transform.forward;
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement