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

Third Person controlle not nitializing

Discussion in 'Scripting' started by Ilseroth, May 22, 2014.

  1. Ilseroth

    Ilseroth

    Joined:
    May 18, 2014
    Posts:
    17
    Ahoy, I am a little bit frustrated, I think I dotted the is and crossed the ts. But evidently I was wrong, as for some reason, ThirdPersonController refuses to initialize which is breaking one of my scripts. It was working perfectly fine until I was rebuilding my player character (new character model) and now it won't initialize. Using the exact same scripts, (I checked) and for some reason it refuses to initialize.

    Code (csharp):
    1. public class AnimationControl : MonoBehaviour {
    2.     public Animator anim;
    3.     public ThirdPersonController cont;
    4.     public weaponattack attacker;
    5.     public float attackTimer = 0;
    6.  
    7.  
    8.     void Start () {
    9.         anim = gameObject.GetComponent<Animator>();
    10.                  //This is where the error is thrown.
    11.         cont = gameObject.GetComponent<ThirdPersonController>();
    12.         attacker = gameObject.GetComponentInChildren<weaponattack>();
    13.     }
    14.    
    15.  
    16.     void FixedUpdate () {
    17.  
    18.         bool move = cont.IsMoving();
    19.         var movespeed = cont.GetSpeed();
    20.         if(Input.GetMouseButtonDown(0)  anim.GetFloat ("Attack") == 0  attackTimer == 0)
    21.         {
    22.             attackTimer = 1;
    23.             anim.SetFloat("Attack", 1);
    24.  
    25.         }
    26.         else if (anim.GetFloat ("Attack") == 1)
    27.         {
    28.             StartCoroutine(animWait());
    29.         }
    30.         if (attackTimer == 1)
    31.         {
    32.             StartCoroutine(attackWait());  
    33.         }
    34.  
    35.         if(move  movespeed <  5)
    36.             anim.SetFloat("Speed", 1);
    37.         else if(move  movespeed >  5)
    38.             anim.SetFloat("Speed", 2);
    39.         else
    40.             anim.SetFloat("Speed", 0);
    41.     }
    Theres more but it is just functions, this is where the "problem" is allegedly... It is the same as it was, I would include a picture of the character very clearly having a third person controller attached to him, but you can just take my word that he definitely has one. This code worked until I made a new player character. the old one is gone, so there is no conflict.
     
    Last edited: May 22, 2014
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    what is the error?

    do you have an animator component setup on the character?
     
  3. Ilseroth

    Ilseroth

    Joined:
    May 18, 2014
    Posts:
    17
    ObjectRefrence not set to an instance of an object

    And yes, the animator component works fine, he is defaulting to his idle animation quite nicely.

    The issue is, allegedly, that he doesnt have a ThirdPersonController attatched to the object... but there is $4N7Km4Z.png
     
    Last edited: May 22, 2014
  4. Ilseroth

    Ilseroth

    Joined:
    May 18, 2014
    Posts:
    17
    Fixed the problem, at some point during the project I downloaded a c# version of the thirdpersoncontroller, and accidently put it in the folder with my assets. I was applying the JS script onto the model, but my c# code was defaulting to calling the unused C# script, which wasn't on the character. So, even though I had a thirdpersoncontroller, it wasn't the thirdpersoncontroller that the game was looking for.