DonDeer
February 23, 2013, 7:36pm
1
Uhm… why? Why do I get the error: Unexpected char: 0xAD (13,65)
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded)
{
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
Your line 13 is the one:
moveDirection = transform.TransformDirection(moveDirection);
You’ve somehow got an invisible soft hyphen inbetween the i and o of your moveDirection
at the end of the line. Just select that variable, delete it, and re-enter it using your keyboard.
Got the same problem it says (23,58) Unexpected char: 0xAD heres my script
#pragma strict
var target : Transform;
var moveSpeed = 3;
var rotationSpeed = 3;
var attackThreshold = 3;
var chaseThreshold = 10;
var giveUpThreshold = 20;
var attackRepeatTime = 1;
var explosionPrefab : Transform;
private var chasing = false;
private var attackTime = Time.time;
var myTransform : Transform;
function Awake()
{
myTransform = transform;
}
function Start()
{
target = GameObject.FindWithTag("Player").transform;
}
function OnCollisionEnter(collision : Collision)
{
if(countenermyhits == 3){*/ Destroy (gameObject);
}
function Update () {
var dist = (target.position - myTransform.position).magnitude; if (chasing) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
if (dist greaterthan giveUpThreshold) { chasing = false; }
if (dist lessthan attackThreshold && Time.time greaterthan attackTime) {
Instantiate(explosionPrefab,transform.position, transform.rotation); Destroy (gameObject); attackTime = Time.time + attackRepeatTime; } } else {
if (dist lessthan chaseThreshold) { chasing = true; } }
}