Hello !
I came across a strange problem today. I’ve searched for some times but found nothing about my problem. I think i’m just missing something but can’t understand what.
Here’s the thing : for a basic school project, i’m using the AIthirdperson controller, found in the standard asset. With this prefab (and script), you just have to drop a Transform in the variable “target” and the character will walk to that transform. I wanted to change this transform via another script but when I’m trying to access the “AICharacterControl” script i get an error “this name doesn’t exist in the current context”…Why ?
Thanks!
using UnityEngine;
using System.Collections;
using System;
public class waypoint_test : MonoBehaviour {
public GameObject PNJ;
public AICharacterControl target_variable;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
The AI script
using System;
using UnityEngine;
using System.Collections;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof (NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
public NavMeshAgent agent { get; private set; } // the navmesh agent required for the path finding
public ThirdPersonCharacter character { get; private set; } // the character we are controlling
public Transform target; // target to aim for
private void Start()
{
// get the components on the object we need ( should not be null due to require component so no need to check )
agent = GetComponentInChildren<NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
agent.updateRotation = false;
agent.updatePosition = true;
}
private void Update()
{
if (target != null)
agent.SetDestination(target.position);
if (agent.remainingDistance > agent.stoppingDistance)
character.Move(agent.desiredVelocity, false, false);
else
character.Move(Vector3.zero, false, false);
}
public void SetTarget(Transform target)
{
this.target = target;
}
}
}