[2D platform game, new to Unity and C#]
I’ve learned how to use SimpleMove to control my character with arrow keys. I’ve heard that you can also use it for objects that move around a level.
In my case, I need my object to move around randomly on the X plane. I’ve tried modifying the code below to detach SimpleMove from input keys, but I couldn’t make it work. I’ve posted the original code that I’m using for my input-controlled character. Does anyone know how to transform this code into something I can use for an NPC who wanders around randomly?
Thanks!
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class Movement : MonoBehaviour {
public float speed = 3.0F;
public int creature_type = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent<CharacterController>();
Vector3 forward = transform.TransformDirection(Vector3.right);
float curSpeed = speed * Input.GetAxis("Horizontal");
controller.SimpleMove(forward * curSpeed);
}
}