- Home /
Moving and Attacking
Hi, so I will explain the situation at hand but here's the error I'm getting:
Control+c__Iterator0.MoveNext () (at Assets/Scripts/Player/Control.cs:62) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) Control:Update() (at Assets/Scripts/Player/Control.cs:108) I have in my Control script: movement via raycasting. One ray selects and the other moves. My problem arises with the MOVEMENT one. Within that movement method I have added a conditional if statement which says that if the movement ray makes contact with a "Goblin" gameObject, then some other logic in another script should be run. Here is that method: IEnumerator MovePlayer () { //selected bool becomes true if the leftray hits the "player" object. if(selected == true) { //Cast a ray from the mouse position on the screen, get hit info. if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {NullReferenceException: Object reference not set to an instance of an object
if (hit.transform.CompareTag ("Goblin")) { fightEnemy.EngageHostile(); } else {
clickPos = hit.point;
//While the distance between the ray collision and the player is > thant 0.001f: while (Vector3.Distance(clickPos, player.transform.position)>0.001f) {
//create float and equal the speed Time.deltaTime float step = speed Time.deltaTime;
//Sends the player towards the ray collision. player.transform.position = Vector3.MoveTowards(player.transform.position, clickPos, step); yield return new WaitForEndOfFrame(); }
} } } } If you could help, that'd be great!
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I know C#, but what Unity methods should I learn? 2 Answers
Distribute terrain in zones 3 Answers
Rays and tags help? 1 Answer
Fading To New Scene Problem? 1 Answer