- Home /
EnemyHover Script Error?
So i have this script here:
using UnityEngine;
using System.Collections;
public class EnemyHover : MonoBehaviour
{
public GameObject player;
public int attackRange;
void OnMouseOver()
{
if (Input.GetMouseButton(0))
{
if (Vector3.Distance(player.position, transform.position) > attackRange)
{
[Here put the code to move player towards a target, I recommend making a "Movement" script that goes on the player and here you call a function on the Players Movement Script to move him to this object]
[PsuedoCode]
player.GetComponent().Move(transform.position);
}
else
{
[Here put the code to attack, I once again recommend creating an "Attack" script and adding it to the player and calling a function on it that makes it attack, also stop the player from moving]
[PsuedoCode]
player.GetComponent().StopMovement();
player.GetComponent().attack(gameObject);
}
}
}
}
For the Movement code i use transform.position = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime); but i get so many errors with it alone. What am i doing wrong? What i want to do is have the player attack the enemy when i press the left click on the enemy and also stop at a certain distance before the enemy.
Comment
Alright so i make the script like this:
using UnityEngine; using System.Collections;
public class EnemyHover : $$anonymous$$onoBehaviour {
public GameObject player;
public int attackRange;
void On$$anonymous$$ouseOver(){
if (Input.Get$$anonymous$$ouseButton(0)){
if (Vector3.Distance(player.position, transform.position) > attackRange){
transform.position = Vector3.$$anonymous$$oveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
player.GetComponent().$$anonymous$$ove(transform.position);
}
}
}
}
And i get the errors seen in this screenshot. I know about the variable errors i get. I think i can fix them those myself :P