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);
}
}
}