Search Unity

Questions I just cannot answer

Discussion in 'Scripting' started by AaronC, Aug 2, 2006.

  1. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Okay guys, Im sure you will find this easy.
    My sub cruises along at this speed:
    Code (csharp):
    1.  
    2. function Update() {
    3.     transform.Translate(0, 0 * Time.deltaTime, 1.5);
    4. }
    5.  
    And when it hits something, I want to destroy the sub,
    Code (csharp):
    1. var subDead : Transform;
    2. function OnCollisionEnter ()
    3. {
    4.    Destroy (gameObject);
    5.    Instantiate (subDead, transform.position, transform.rotation);
    6. }
    Basicly Im trying to use the second script to either destroy (or for the benefit of my learning curve, disable) the first script

    Can anyone see where Im going wrong?Thanks
    AC
     
  2. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    It would help if you told us what happens, rather than "it doesn't work." Does ths sub move wrong? Does it pass through things rather than collide?

    This piece of math looks suspicious: 0 * Time.deltaTime

    If it passes through things, maybe your sub or the other objects don't have a rigidbody component on them?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As mentioned in the other thread, change that to (0, 0, 1.5 * Time.deltaTime).

    I'm wondering why you want to destroy the first script? Once you've destroyed gameObject, it's not going to be moving along its Z axis any more (since it doesn't exist), and subDead doesn't inherit the first script, so it won't move when you've instantiated it (unless you specifically add a force to it). Seems to me that part is fine the way it is.

    --Eric