- Home /
The question is answered, right answer was accepted
So I'm trying to like make a game in which an gameobject with a certain tag gains health if they collide with another gameobject with the tag such as "healthCube"
I have started learning unity a few days ago and at that point in where I use the GetComponent function in unity. I am trying to change the Health value in a secondary player object whenever it collides with an object attached to a tag named "healthCube". There's this error code I see and I don't know how to fix it .(I might just not know what the error means so in that case could you please tell me what this error means) The error code I keep on receiving in the Console section is "Assets\cubeFunction.cs(13,38): error CS1501: No overload for method 'GetComponent' takes 1 arguments"
here is the script on the healthCube itself
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class healthForPlayer : MonoBehaviour
{
public int generalHealth = 100;
public int Damage = 10;
public int addHitpoints = 50;
void Awake()
{
Debug.Log(generalHealth);
}
void Update()
{
if ( generalHealth == 0)
{
Destroy(gameObject);
}
}
private void OnCollisionEnter (Collision other)
{
if(other.gameObject.tag == "Bullet")
{
generalHealth -= Damage;
Debug.Log(generalHealth);
}
}
}
and here is the script on the secondary player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class healthForPlayer : MonoBehaviour
{
public int generalHealth = 100;
public int Damage = 10;
public int addHitpoints = 50;
void Awake()
{
Debug.Log(generalHealth);
}
void Update()
{
if ( generalHealth == 0)
{
Destroy(gameObject);
}
}
private void OnCollisionEnter (Collision other)
{
if(other.gameObject.tag == "Bullet")
{
generalHealth -= Damage;
Debug.Log(generalHealth);
}
}
}
sry if it is a very rookie mistake I am very new to unity
You posted the same script twice. Can I see the secondary player script and then maybe I can help you?