Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Trouble instantiating a prefab.

Discussion in 'Editor & General Support' started by The MC, Feb 16, 2006.

  1. The MC

    The MC

    Joined:
    Oct 31, 2005
    Posts:
    105
    I'm working with the ShootBallFPS script, but I'd like to change the ball that gets shot. I set my new ball (cannon_shot) up as a Rigidbody, and a prefab, but it isn't an available choice when I go to the inspector unless it is also on the stage.

    Is there something else I need to do, or can I only Instantiate objects that are present on the stage?


    Code (csharp):
    1.  
    2. var ball : Rigidbody;
    3. var velocity = 30.0;
    4.    
    5. function Update ()
    6. {
    7.     if (Input.GetButtonDown ("Fire1"))
    8.     {
    9.         var shoot :Rigidbody = Instantiate (ball, transform.position, transform.rotation);
    10.         shoot.velocity = transform.rotation * Vector3.fwd * velocity;
    11.     }
    12. }
    13.  
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Just drag the prefab from the project window into the inspector.
     
  3. The MC

    The MC

    Joined:
    Oct 31, 2005
    Posts:
    105
    Ah, I see.... well.... isn't my face red. Thanks for the help. Appreciate it.