I’m pretty new to Unity and have been following a tutorial series. Everything has been going fine up until video 22 and I’m having a script problem. My question is two part.
Firstly when I initially downloaded Unity I must have installed Unity 5.5. It would seem that the tutorial I am following is using 5.0. Up till now everything worked fine but it would seem that there are some things different when it comes to scripting. First question, If I reinstall Unity with version 5.0 to be using the same version my tutorial is will I loose all my stuff up till now?
Second quest: If it is not possible to do that without loosing all my progress what could be changed about this script to make it work with Unity 5.5?
The error I am getting is on the detectionLayer part. When I scroll over it, it says (Argument3: cannot convert from ‘UnityEngine,LayerMask’ to ‘UnityEngine.Coliider[ ]’)
I have went over it plenty of time and I dont think I have anything different that what my tutorial has so I assume it is something about the scripting terminology changing in Unity 5.5? Here is the script I have. Thanks for any help, dorry to burden you guys.
[code=CSharp]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
namespace Chapter1
{
public class Enemy_Chase : MonoBehaviour
{
public LayerMask detectionLayer;
private Transform myTransform;
private NavMeshAgent myNavMeshAgent;
private Collider[] hitColliders;
private float checkRate;
private float nextCheck;
private float detectionRadius = 10;
// Use this for initialization
void Start()
{
SetInitialReferences();
}
// Update is called once per frame
void Update()
{
CheckIfPlayerInRange();
}
void SetInitialReferences()
{
myTransform = transform;
myNavMeshAgent = GetComponent<NavMeshAgent>();
checkRate = Random.Range(0.8f, 1.2f);
}
void CheckIfPlayerInRange()
{
if (GetComponent<NavMeshAgent>().enabled == true)
{
nextCheck = Time.time + checkRate;
hitColliders = Physics.OverlapSphereNonAlloc(myTransform.position, detectionRadius, detectionLayer);
if (hitColliders.Length > 0)
{
myNavMeshAgent.SetDestination(hitColliders[0].transform.position);
}
}
}
}
}
[/code]