Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

RTS/MOBA movement script error,Error in RTS/moba movement script

$
0
0
Hi, I am having an error with a RTS/MOBA movement script. Here is the scipt: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class Movement : MonoBehaviour { Camera cam; public LayerMask Ground; public NavMeshAgent playerAgent; void Awake () { cam = Camera.main; } void Update () { if (Input.GetMouseButtonDown(1)) { playerAgent.SetDestination(GetPointUnderCursor()); } } private Vector3 GetPointUnderCursor() { Vector2 screenPosition = Input.mousePosition; Vector3 mouseWorldPosition = cam.ScreenToWorldPoint(screenPosition); RaycastHit hitPosition; Physics.Raycast(mouseWorldPosition, cam.transform.forward, out hitPosition, 100000, Ground); return hitPosition.point; } } there is the error: > NullReferenceException: Object> reference not set to an instance of an> object Movement.GetPointUnderCursor ()> (at Assets/Scripts/Movement.cs:32)> Movement.Update () (at> Assets/Scripts/Movement.cs:24) Could someone help me?

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>