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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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. }