Hello Guys, I am Issa.
I was following the (Shooting with Raycasts) – Unity Tutorial
By Brackeys. At 8:06 time he said to tap the crate 5 times.
But I had this error :
(AssetsScriptsGun.cs(33,30): error CS1503: Argument 1: cannot convert from ‘damage1’ to ‘float’).
My code was:
Gun.cs :
using UnityEngine;
public class Gun : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
public Camera fpsCam;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
damage1 damage = hit.transform.GetComponent<damage1>();
if(damage != null)
{
damage.TakeD(damage);
}
}
}
}
damage1.cs :
using UnityEngine;
public class damage1 : MonoBehaviour
{
public float health = 50f;
public void TakeD (float amount)
{
health -= amount;
if(health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}
Please can anyone help me!!!