I set a public game object value to a empty called Player with parts, I tried to reference the Player and print the X value of player (Player.Transform.Position.X) and it is telling me “'‘GameObject’ does not contain a definition for ‘Name’ and no accessible extension method ‘Name’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or a assemble reference?)”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public GameObject Player;
public float speed = 1;
public float jumpheight = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.RightArrow))
{
print("Got Right Arrow");
transform.Rotate(0, speed, 0 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
print("Got Left Arrow");
transform.Rotate(0, -speed, 0 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.W))
{
print("Got W");
transform.Translate(0, 0, -speed * Time.deltaTime);
print(this.Player.Name);
}
if (Input.GetKeyDown(KeyCode.Space))
{
print("Got Space");
transform.Translate(0, jumpheight, 0 * Time.deltaTime);
}
}
}
(I have only been programming in C# for a week by now, I may be forgetting something obvious)