Ako upraviť kód kde sa postava zastaví pri bode 3 napr na 9 sekúnd a po uplinutí času by sa mala pohnúť.
Hodnotu načíta 9s Ale nechce správne odpočitávať timer -= Time.deltaTime; tu je kód
Problematická časť kódu je vyznačená tučným písmom. Ďakujem za rady
#pragma strict
public var wayPoints : Transform[];
var enemy: GameObject;
var player: GameObject;
public var vehicleSpeed : float;
public var curWayPoint : int;
public var turningSpeed : float;
public var doPatrol : boolean = true;
public var target : Vector3;
public var moveDirection : Vector3;
public var Velocity : Vector3;
var minvzdialenostsledovania :float=3;
var moveSpeed :float=3;
private var animator:Animator;
var idleAnimation:AnimationClip;
var walkAnimation:AnimationClip;
var attackAnimation:AnimationClip;
var diem:AnimationClip;
var rb: Rigidbody;
private var nav:NavMeshAgent;
var stop:boolean= true;
public var timer:float;
function Start()
{
var animation : Animation;
animator=GetComponent(Animator);
rb = GetComponent.<Rigidbody>();
}
function Update()
{
var distance = Vector3.Distance(enemy.transform.position, player.transform.position);
Debug.Log(distance);
if(distance>=3 && distance<=4 ){
Debug.Log("pozoruje"+distance);
lookAtPlayer();
rb.velocity=Vector3.zero;
GetComponent.<Animation>().Play("Idle_02");
GetComponent.<Animation>().Stop("Walk");
}else if(distance>4){
Debug.Log("strazi objekt"+distance +"bod"+curWayPoint);
/*tu sa otoci*/
rigidbody.rotation = Quaternion.Slerp(enemy.transform.rotation,Quaternion.LookRotation(-moveDirection),turningSpeed * Time.deltaTime);
Waipointss();
}
if(distance<=3){
GetComponent.<Animation>().Play("Walk");
GetComponent.<Animation>().Stop("Idle_02");
Debug.Log("prenasleduje"+distance);
enemy.transform.position += enemy.transform.forward * 1 * Time.deltaTime;
lookAtPlayer();
}else{
//Waipointss();
}
}
function Waipointss(){
if(curWayPoint < wayPoints.Length)
{
target = wayPoints[curWayPoint].position;
moveDirection = target - enemy.transform.position;
Velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
curWayPoint++;
}
else
{
Velocity = moveDirection.normalized * vehicleSpeed;
}
}
else
{
if(doPatrol)
{
curWayPoint = 0;
}
else
{
Velocity = Vector3.zero;
}
}
rigidbody.velocity = Velocity;
/*tu sa otoci*/
rigidbody.rotation = Quaternion.Slerp(enemy.transform.rotation,Quaternion.LookRotation(moveDirection),turningSpeed * Time.deltaTime);
if(curWayPoint==3){
timer = 9.0;
if (timer <= 0) {
timer -= Time.deltaTime;
//We only need to update the text if the score changed.
GetComponent.<Animation>().Play("Walk");
//Reset the timer to 0.
timer = 0.0;
}else{
Debug.Log("timer"+timer);
GetComponent.<Animation>().Stop("Walk");
GetComponent.<Animation>().Play("Idle_02");
rb.velocity=Vector3.zero;
Debug.Log("cas"+timer);
}
}
GetComponent.<Animation>().Play("Walk");
}
function lookAtPlayer(){
var relativePos = player.transform.position-enemy.transform.position ;
var rotation = Quaternion.LookRotation(relativePos);
enemy.transform.rotation = rotation;
}