Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

I am currnetly making a bullet script but i am having issues accsesing the health variable in the "Health" script , i will post both health and bullet script and the error i am having

$
0
0
public float speed; private Transform player; private Vector2 target; public float damage = 2.0f; public GameObject CoolGuy; private Health access; // Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; target = new Vector2(player.position.x, player.position.y); access = CoolGuy.GetComponent(); } // Update is called once per frame void Update() { transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime); if (transform.position.x == target.x && transform.position.y == target.y) ; { } } void OnCollisionEnter2D(Collision2D collisionInfo) { if (collisionInfo.collider.tag == "Player") { CoolGuy.Health -= 1; } } } Error: error CS1061: 'GameObject' does not contain a definition for 'Health' and no accessible extension method 'Health' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?) Health script: { public int health = 10; public int Maxhealth = 10; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (health <= 0) { Destroy(gameObject); } if (health > Maxhealth) { health = Maxhealth; } } public void TakeDamage() { health -= 1; if (health <= 0) { Destroy(gameObject); } } } I do not know how to reffrence the Health script with the Gameobject called "CoolGuy"

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>