- Home /
Assets/characterFollower.cs(21,29): error CS0118: `characterFollower.walkCollider' is a `field' but a `type' was expected
i have two character in my game, one is the player and the another one is a guy that i want it to follow the player; i am making a script to change the velocity of the follow script that i have with two triggers (one for the walking speed and the another one for the running speed) so i want that if the character exits the walk trigger it will go at the walk speed specified in the script, if the character exits the run trigger it will go at the run speed also specified in the script and the same for entering in both triggers. So i have this error "Assets/characterFollower.cs(21,29): error CS0118: characterFollower.walkCollider' is a field' but a type' was expected" This is my follow script: using UnityEngine; using System.Collections;
public class Follow : MonoBehaviour {
public Transform target;
public Transform myTransform;
public float rotationSpeed = 3;
public float moveSpeed = 3;
void Awake(){
myTransform = transform;
}
// Use this for initialization
void Start () {
target = GameObject.FindWithTag("Character").transform;
}
// Update is called once per frame
void Update () {
var lookDir = target.position - myTransform.position;
lookDir.y = 0; // zero the height difference
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}'
And this is what i am trying
`using UnityEngine; using System.Collections;
public class characterFollower : MonoBehaviour {
public Collider walkCollider;
public Collider runCollider;
public Follow followScript;
public float walkSpeed = 6;
public float runSpeed = 18;
public float idleSpeed = 0;
public string characterTag;
void Start () {
followScript.moveSpeed = idleSpeed;
}
// Update is called once per frame
void OnTriggerExit (walkCollider Trigger)
{
if(Trigger.tag == characterTag)
{
followScript.moveSpeed = walkSpeed;
}
}
void OnTriggerEnter(walkCollider Trigger)
{
if(Trigger.tag = characterTag)
{
followScript.moveSpeed = idleSpeed;
}
}
void OnTriggerExit(runCollider Trigger)
{
if(Trigger.tag = characterTag)
{
followScript.moveSpeed = runSpeed;
}
}
void OnTriggerEnter(runCollider Trigger)
{
if(Trigger.tag = characterTag)
{
followScript.moveSpeed = walkSpeed;
}
}
}'
Your answer