- Home /
Cant access a gameobject's position
Getting this error when trying to acces a gameobject attached to a gameobject in unity.
Error CS1061: 'UnityEngine.GameObject' does not contain a definition for 'position' and no extension method 'position' accepting a first argument of type 'UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp)
Here is the code used: (error is on groundCheck.position) using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
GameObject groundCheck;
public bool grounded;
public int jumpHeight = 5;
void Start () {
}
// Update is called once per frame
void Update () {
grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
if (Input.GetKeyDown (KeyCode.Space) && grounded){
rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, jumpHeight);
}
}
}
Ok, so I did that. I added a smaller trigger collider on,it is colliding with "Ground" layer objects... It still wont set to true and I cant figure out why.
Answer by Jeff-Kesselman · Jun 11, 2014 at 12:21 AM
The error is precisely what it says it is. Objects of type GameObject (such as groundCheck) do not have a position field.
http://docs.unity3d.com/ScriptReference/GameObject.html
Perhapse you meant groudCheck.transform.position ?
position is part of the transform of the game object so it would be gameObject.transform.position;
Your answer
Follow this Question
Related Questions
Getting Error I don't Understand - 'position' is not a member of 'UnityEngine.GameObject[]'. 1 Answer
It is not possible to invoke an expression of type 'UnityEngine.GameObject'? 1 Answer
Y-Positionen angleichen / Align the Y positions 0 Answers
I want to move a cube with rotation but I find this problem 1 Answer
If gameobject moves do this 1 Answer