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

Question unity 3d error CS1061 game object does not contain definition for transform

Discussion in 'Scripting' started by Claudio2827, Jan 9, 2023.

  1. Claudio2827

    Claudio2827

    Joined:
    Oct 26, 2022
    Posts:
    2
    Im trying to make a simple moving platform for my game but no mater what i do, ( FindGameObjectWithTag... etc) it comes up with this error is there anything to be done or should i start from the begining or am i missing something really basic
    (i am new to unit and this is my first game)
    Code (CSharp):
    1. public class WaypointFollower : MonoBehaviour
    2. {
    3.     [SerializeField] GameObject[] waypoints;
    4.     int currentWaypointIndex = 0;
    5.  
    6.     [SerializeField] float speed = 1f;
    7.  
    8.     void Update()
    9.     {
    10.         if (Vector3.Distance(transform.position, waypoints[currentWaypointIndex].tranform.position) < .1f)
    11.         {
    12.             currentWaypointIndex++;
    13.             if(currentWaypointIndex >= waypoints.Length)
    14.             {
    15.                 currentWaypointIndex = 0;
    16.             }
    17.         }
    18.  
    19.         transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypointIndex].transform.position, speed * Time.deltaTime);
    20.     }
    21. }
     
    Last edited: Jan 9, 2023
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,622
    In actual fact it likely says "does not contain definition for tranform"

    Note that the error also tells you both the line and column so given the error you can locate exactly where it means.

    If you had used code-tags here (please always do this) then I'd be able to tell you the line above but it's likely this line:

    Code (CSharp):
    1. if (Vector3.Distance(transform.position, waypoints[currentWaypointIndex].tranform.position) < .1f)
    You have to be 100% accurate on your typing, the compiler won't forgive you. ;)
     
  3. Claudio2827

    Claudio2827

    Joined:
    Oct 26, 2022
    Posts:
    2
    thank you very much!!!! MelvMay i will give this a go.

    (also i have rectified the formating error)
     
    MelvMay likes this.