Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need A Little Help

Discussion in 'Scripting' started by kurlzy, Jun 16, 2014.

  1. kurlzy

    kurlzy

    Joined:
    May 25, 2014
    Posts:
    8
    Hello im not sure if i put this in the correct area or not if so im sorry.... im still relatively new to unity and ive came across an error i can quiet figure out if my life depends on it any help is appertiated..



    and this is the code that seem to be affected by it:

    Code (JavaScript):
    1. var speed = 3.0;
    2. var rotateSpeed = 3.0;
    3. var bullitPrefab:Transform;
    4.  
    5. function Update ()
    6. {
    7.     var controller : CharacterController = GetComponent(CharacterController);
    8.    
    9.     //Rotate around y - axis
    10.     transform.Rotate(0,Input.GetAxis("Horizontal") * rotateSpeed, 0);
    11.    
    12.     //Move forward / Backward
    13.     var forward = transform.TransformDirection(Vector3.forward);
    14.     var curSpeed = speed * Input.GetAxis ("Vertical");
    15.     controller.SimpleMove(forward * curSpeed);
    16.    
    17.     if(Input.GetButtonDown("Jump"))
    18.     {
    19.         var bullit = Instantiate(bullitPrefab, GameObject.Find("SpawnPoint").transform.postion, Quaternion.identity);
    20.     }
    21.    
    22. }
    23.  
    24.  

    thanks in advance kurzly...
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    welcome kurzly. not to be rude but have you tried googling the error.
    you will find out you are making a null reference. which means you are pointing to something that is null.
    this happens in your case in this line:
    Code (CSharp):
    1.  var bullit = Instantiate(bullitPrefab, GameObject.Find("SpawnPoint").transform.postion, Quaternion.identity);
    which mean that: or your bullitPrefab is empty or the GameObject.Find("SpawnPoint") doesn't find it's object.
     
  3. kurlzy

    kurlzy

    Joined:
    May 25, 2014
    Posts:
    8
    yeah ive tried googling here left and right i just cant seem to see wats missing? would it help if i pose my hierachy plane?
     
  4. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Null reference means that a gameObject you are referencing is empty. In this case it seems to be the bullitPrefab. Out of experience I know that Google is your friend with this error.
     
  5. kurlzy

    kurlzy

    Joined:
    May 25, 2014
    Posts:
    8


    i don't get what your getting at exactly ive added the object in just doesn't seem to be registering anymore tips?
     
  6. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    In your screenshot 'spawnPoint' looks to have a lowercase S, while your searching for 'SpawnPoint' with a capital, so can't find it.
     
  7. kurlzy

    kurlzy

    Joined:
    May 25, 2014
    Posts:
    8
    yeah sorry i meant to fix that but still the same issue really check spelling on both ends and still nothing
    fixed that already rechecked and still the same error
     
  8. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    transform.postion is not correct in the Instantiate
     
    NomadKing likes this.
  9. kurlzy

    kurlzy

    Joined:
    May 25, 2014
    Posts:
    8
    care to correct me then?
     
  10. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    It's not spelt correctly.

    A tip for future reference, use:
    Code (csharp):
    1. #pragma strict
    at the top of any JS scripts you write. It'll give you better compiler errors for spotting this kind of thing :)
     
  11. kurlzy

    kurlzy

    Joined:
    May 25, 2014
    Posts:
    8
    thank you so much lolz ive just been over looking this waaaay to much thanks for the help all sorry to seem like a dummy here ><