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

'Transform' does not contain a definition for 'GetPosition'

Discussion in 'Scripting' started by bestjukky, Jun 20, 2020.

Thread Status:
Not open for further replies.
  1. bestjukky

    bestjukky

    Joined:
    Jun 20, 2020
    Posts:
    6
    The Error Message is:
    (28,37): error CS1061: 'Transform' does not contain a definition for 'GetPosition' and no accessible extension method 'GetPosition' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)

    My Script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LevelGeneratorScript : MonoBehaviour {
    6.  
    7.     private const float PLAYER_DISTANCE_SPAWN_LEVEL_PART = 20f;
    8.  
    9.     [SerializeField] private List<Transform> levelPartList;
    10.     [SerializeField] private Transform levelPart_Start;
    11.     [SerializeField] private Transform player;
    12.  
    13.     private Vector3 lastEndPosition;
    14.  
    15.     private void Awake()
    16.     {
    17.         lastEndPosition = levelPart_Start.Find("EndPosition").position;
    18.  
    19.         int startingSpawnLevelParts = 5;
    20.         for (int i = 0; i < startingSpawnLevelParts; i++)
    21.         {
    22.             SpawnLevelPart();
    23.         }
    24.     }
    25.  
    26.     private void Update()
    27.     {
    28.         if (Vector3.Distance(player.GetPosition(), lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART)
    29.         {
    30.  
    31.             SpawnLevelPart();
    32.         }
    33.     }
    34.  
    35.     private void SpawnLevelPart()
    36.     {
    37.         Transform chosenLevelPart = levelPartList[Random.Range(0, levelPartList.Count)];
    38.         Transform lastLevelPartTransform = SpawnLevelPart(chosenLevelPart, lastEndPosition);
    39.         lastEndPosition = lastLevelPartTransform.Find("EndPosition").position;
    40.     }
    41.  
    42.     private Transform SpawnLevelPart(Transform levelPart, Vector3 spawnPosition)
    43.     {
    44.         Transform levelPartTransform = Instantiate(levelPart, spawnPosition, Quaternion.identity);
    45.         return levelPartTransform;
    46.     }
    47. }
    48.  
    I am new to coding and i think it's not a big error but i can't figure it out.
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    replace getposition() with transform.position
     
  3. bestjukky

    bestjukky

    Joined:
    Jun 20, 2020
    Posts:
    6
    (28,47): error CS1955: Non-invocable member 'Transform.position' cannot be used like a method.
    Now it's so.

    Code with Problem
    Code (CSharp):
    1.  private void Update()
    2.     {
    3.         if (Vector3.Distance(player.transform.position(), lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART)
    4.         {
    5.  
    6.             SpawnLevelPart();
    7.         }
    8.     }
    9.  
    10.     private void SpawnLevelPart()
    11.     {
    12.         Transform chosenLevelPart = levelPartList[Random.Range(0, levelPartList.Count)];
    13.         Transform lastLevelPartTransform = SpawnLevelPart(chosenLevelPart, lastEndPosition);
    14.         lastEndPosition = lastLevelPartTransform.Find("EndPosition").position;
    15.     }
    16.  
    17.     private Transform SpawnLevelPart(Transform levelPart, Vector3 spawnPosition)
    18.     {
    19.         Transform levelPartTransform = Instantiate(levelPart, spawnPosition, Quaternion.identity);
    20.         return levelPartTransform;
    21.     }
    22. }
    23.  
     
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    remove ()
     
  5. Necyl

    Necyl

    Joined:
    Jun 20, 2020
    Posts:
    1
    please be more specific
     
  6. bestjukky

    bestjukky

    Joined:
    Jun 20, 2020
    Posts:
    6
    Error:
    'Transform' does not contain a definition for 'remove' and no accessible extension method 'remove' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)

    Not Working
    Code:

    Code (CSharp):
    1. private void Update()
    2.     {
    3.         if (Vector3.Distance(player.transform.remove(), lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART)
    4.         {
    5.  
    6.             SpawnLevelPart();
    7.         }
    8.     }
    9.  
    10.     private void SpawnLevelPart()
    11.     {
    12.         Transform chosenLevelPart = levelPartList[Random.Range(0, levelPartList.Count)];
    13.         Transform lastLevelPartTransform = SpawnLevelPart(chosenLevelPart, lastEndPosition);
    14.         lastEndPosition = lastLevelPartTransform.Find("EndPosition").position;
    15.     }
    16.  
    17.     private Transform SpawnLevelPart(Transform levelPart, Vector3 spawnPosition)
    18.     {
    19.         Transform levelPartTransform = Instantiate(levelPart, spawnPosition, Quaternion.identity);
    20.         return levelPartTransform;
    21.     }
    22. }
    23.  
     
  7. FurkanSz

    FurkanSz

    Joined:
    Dec 27, 2019
    Posts:
    9
    Code (CSharp):
    1. if (Vector3.Distance(player.transform.position, lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART)
    2.         {
    3.             SpawnLevelPart();
    4.         }
     
  8. bestjukky

    bestjukky

    Joined:
    Jun 20, 2020
    Posts:
    6
    Oh thank you :)
     
  9. Gaah_HW

    Gaah_HW

    Joined:
    May 4, 2021
    Posts:
    2
    está dando o erro

    erro CS1061: 'Transformar' não contém uma definição para 'posição' e nenhum método de extensão acessível 'posição' aceitando um primeiro argumento do tipo 'Transformar' pode ser encontrado (está faltando uma diretiva de uso ou uma referência de assembly?)

    Não sei como resolver você pode me ajudar ??

    [code = CSharp] using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class PlayerController: MonoBehaviour
    {
    // Start é chamado antes da primeira atualização de frame
    void Start ()
    {

    }

    // A atualização é chamada uma vez por quadro
    void Update ()
    {
    if (Input.GetKey (KeyCode.RightArrow))
    {

    transform.positon = transform.position + new Vector3 (1, 0, 0);

    }
    }

    }[/código]
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    positon -> position

    Please don't hijack one-year-old threads. Start your own new post... it is FREE.
     
  11. ExtraINC

    ExtraINC

    Joined:
    Dec 19, 2021
    Posts:
    2
    hi, I know it's an old post but Im dealing with the same code and it doesnt work for me. no errors but just no response
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Then start a new post of your own. It's not hard. It's actually FREE.

    When you post, keep this in mind:

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  13. MarcusTy999

    MarcusTy999

    Joined:
    Jan 31, 2022
    Posts:
    2
    I have error CS1061 and here is the code. any idea what the problem is?

    using UnityEngine;
    public class FollowPlayer : MonoBehaviour
    {
    public Transform player;
    // Update is called once per frame
    void Update()
    {
    Debug.Log(player.postion);
    }
    }
     
  14. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    I wonder if this is a troll post?

    Check your spelling.
     
  15. MarcusTy999

    MarcusTy999

    Joined:
    Jan 31, 2022
    Posts:
    2
    no i'm actually new. i dont understand what's wrong and I don't see any spelling mistakes.
     
  16. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,572
    How is that possible that you end up here on this ancient thread and you actually have the same spelling mistake that Gaah_HW mad over a year ago and you did not spot it since it was literally mentioned in this thread?. Kurt posted this:

    You made the exact same two mistakes. You have the same spelling mistake and you also hijacked this thread... Why do you come to such a thread, when you don't read any of the posts in it?
     
  17. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,003
    Closed. Don't necro old threads without reading them. Your error was literally answered 3 posts above your post.
     
Thread Status:
Not open for further replies.