Search Unity

Missing Assembly Reference

Discussion in 'Scripting' started by m_cooman, Dec 24, 2017.

  1. m_cooman

    m_cooman

    Joined:
    Dec 24, 2017
    Posts:
    4


    Following this YouTube tutorial and he explains how to make it so the game manager object ends the game when the player collides with an obstacle. When I try it I get this error code on the PlayerCollision script (it's a component on the player) -

    Assets/Scripts/Player Scripts/PlayerCollision.cs(24,21): error CS0246: The type or namespace name `GameManager' could not be found. Are you missing an assembly reference?

    this is the whole script -

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerCollision : MonoBehaviour {
    4.  
    5.     public PlayerMovement movement;
    6.     public Transform player;
    7.  
    8.  
    9.     public void OnCollisionEnter (Collision collisionInfo )
    10.  
    11.     {
    12.         GameObject varGameObject = GameObject.Find("Player");
    13.  
    14.         if (collisionInfo.collider.tag == "Reset")
    15.         {
    16.             transform.rotation = Quaternion.Euler (0, 90, 0);
    17.         }
    18.  
    19.         if (collisionInfo.collider.tag == "Obstacle")
    20.            
    21.         {
    22.             movement.enabled = false;
    23.             GetComponent<PlayerSteerVis>().enabled = false;
    24.             FindObjectOfType<GameManager>().EndGame();
    25.         }
    26.    
    27.  
    28.     }
    29.  
    30. }
    31.  

    And this is the script I'm referring to on the GameManager object -


    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class GameManagement : MonoBehaviour {
    4.  
    5.     public void EndGame ()
    6.     {
    7.  
    8.         {
    9.             Debug.Log ("GAME OVER");
    10.         }
    11.  
    12.     }
    13. }
    14.  

    On the PlayerCollision script when I begin to type EndGame it comes up on the predictive text type thing so surely it's finding it so why is it saying it can't find the object? I tried re-importing all assets with no success and I've tried to delete the UnityAssemblies folder which is apparently a fix but I can't locate it. The game object is called GameManager and is in the scene, another script on the GameManager allows me to reset the game hitting the spacebar so it's definitely there.

    I'm still new at this but I thought this all made sense so is it a Unity bug or am I missing something?? I really appreciate any help or advice, thank you <3 :D
     
    Last edited: Dec 24, 2017
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
  3. m_cooman

    m_cooman

    Joined:
    Dec 24, 2017
    Posts:
    4
    Sorry I didn't know this was my first post haha, I've corrected it thank you!
     
    Peter77 likes this.
  4. Prastiwar

    Prastiwar

    Joined:
    Jul 29, 2017
    Posts:
    125
    FindObjectOfType means you're searching GameObject existing in scene which have attached GameManager. So, do you have GameObject in scene with this script attached to it?
     
  5. m_cooman

    m_cooman

    Joined:
    Dec 24, 2017
    Posts:
    4
    I believe so, the GameManagement script is attached to the GameManager object

    I just tried attaching the GameManagement script to the Player object as well but the same thing happened
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Code (csharp):
    1. FindObjectOfType<GameManager>().EndGame();
    You're trying to find an instance of type GameManager, but the other class you posted is named GameManagement:
    Code (CSharp):
    1. public class GameManagement : MonoBehaviour {
     
    nakrut777 and m_cooman like this.
  7. m_cooman

    m_cooman

    Joined:
    Dec 24, 2017
    Posts:
    4
    This fixed it! Thank you so much for your help <3 I thought I had to search for the object and it would find the script on it's own, I should've tried that really but I understand now thank you
     
    nakrut777 and Peter77 like this.