Can someone help me? I programmed a script so that a weapon is always pointed at the player, but Unity throws this error: NullReferenceException: Object reference not set to an instance of an object
aim.Update () (at Assets/aim.cs:16)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class aim : MonoBehaviour
{
public Transform target;
private Vector3 calculatettargetpos;
private PLayerMovemondscript playercontroler;
private float angle;
// Update is called once per frame
void Update()
{
calculatettargetpos = playercontroler.move + target.position;
Vector3 targetDir = calculatettargetpos - transform.position;
angle = Mathf.Atan2(targetDir.z, targetDir.x) * Mathf.Rad2Deg;
transform.localRotation = Quaternion.Euler(0f, -angle -180 , 0f);
}
}