Rotation of my enemy How??

Hi....

I have an enemy that goes from PointA to PointB and then from PointB to PointA....

Here is the script..


var pointB : Vector3;

function Start () {
    var pointA = transform.position;
    while (true) {
        yield MoveObject(transform, pointA, pointB, 3.0);
        yield MoveObject(transform, pointB, pointA, 3.0);
    }
}

function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
    var i = 0.0;
    var rate = 1.0/time;
    while (i < 1.0) {
        i += Time.deltaTime * rate;
        thisTransform.position = Vector3.Lerp(startPos, endPos, i);
        yield; 
    }
}


I am new to unity and i need a little help... I want when my enemy goes to PointB to rotate 180 and go back to pointA...but i dont know how to do it...Thank you.

here is what you need, just adding transform.rotate to the script and rotating it across the y axis to turn it around.you had almost exactly right.

but here it is

var pointB : Vector3;
function Start () {    
var pointA = transform.position;    
while (true) {        
yield MoveObject(transform, pointA, pointB, 3.0);
transform.Rotate(0,180,0);
yield MoveObject(transform, pointB, pointA, 3.0);
transform.Rotate(0,180,0);}}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {    
var i = 0.0;    
var rate = 1.0/time;    
while (i < 1.0) {        
i += Time.deltaTime * rate;        
thisTransform.position = Vector3.Lerp(startPos, endPos, i);        
yield;     }}

hope this is what you need!

When adding the

Transform

Make sure that the (x, y, z) is correctly set up. Other wise, try using

Transform(x, Quaternion, z)