Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Bullet : MonoBehaviour
- {
- public GameObject Gun ;
- public Vector3 direction ;
- public void Awake()
- {
- // You can't use Gun yet
- }
- public void Start()
- {
- if( Gun != null )
- Debug.Log("I've been instiated by " + Gun.name ) ;
- }
- public void Update()
- {
- transform.Translate( direction ) ;
- }
- }
- public class Gun : MonoBehaviour
- {
- public void Shoot()
- {
- GameObject instance = Instantiate( bulletPrefab ) ;
- Bullet bullet = instance.GetComponent<Bullet>();
- if( bullet != null )
- {
- bullet.Gun = gameObject;
- bullet.Direction = transform.forward;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement