Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

C# Checking if the gameobject equals an object

Discussion in 'Scripting' started by Jsmucker, Oct 21, 2014.

  1. Jsmucker

    Jsmucker

    Joined:
    Sep 5, 2014
    Posts:
    48
    I am trying to write a code to get the script to check if a gameobject = an object. I am using this code:
    Code (CSharp):
    1. if (gameObject == Transform.Find("Zombie")) {
    2.                         animation.Play ("down");
    3.                 }
    It then gives me an error:
    An object reference is required to access non-static member `UnityEngine.Transform.Find(string)'
    Any ideas on how to fix this?
     
  2. DrSnake

    DrSnake

    Joined:
    Oct 17, 2014
    Posts:
    33
    Arent you looking for this instead of transform?
    Code (CSharp):
    1. if (gameObject == GameObject.Find("Zombie")) {
    2.         animation.Play ("down");
    3. }