I’ve been scripting in c# to make my character attack hostiles. I’ve encountered an error that I have no idea of how to solve. It says “Assets/Scritps/PlayerAttack.cs(22,46): error CS0426: The nested type Distance' does not exist in the type UnityEngine.Vector3’” and I have looked around on google for a while now, but it does not help sadly.
Here is the script
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.F)) {
Attack();
}
}
private void Attack(){
float distance = new Vector3.Distance(target.transform.position, transform.position);
Debug.Log(distance);
if(distance < 2.5f) {
EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
if(eh != null){
eh.AdjustCurrentHealth(-10);
}
}
}
}
Ah, thank you very kindly ^^
– LanshWhy not flag robertbu's answer as accepted if it helped you :)
– Cherno