So I am trying use the Survival Shooter, as base to work on my program but I am running into a issue NullReferenceException: Object reference not to an instance of an object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cyclop_Player_Controller : MonoBehaviour {
public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody rb;
int groundMask;
float camRayLength = 100f;
void Awake()
{
groundMask = LayerMask.GetMask("Ground");
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Move(h, v);
Turning();
Animating(h, v);
}
void Move (float h, float v)
{
movement.Set(h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
rb.MovePosition(transform.position + movement);
}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit groundHit;
if(Physics.Raycast(camRay, out groundHit, camRayLength, groundMask))
{
Vector3 playerToMouse = groundHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
rb.MoveRotation(newRotation);
}
}
void Animating(float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool("IsWalking", walking);
}
}
It might be due how i have the scene set up but I wouldn’t be sure how I be able to tell. I appropriate the assistance cause i been using unity for 1 month so still bit new to it.