Sunday, 9 October 2016

Flip Object to player Face

using UnityEngine;
using System.Collections;

public class FlipHelthEnemy : MonoBehaviour {

//public Transform target;

//public Transform enemy;

bool facingRight = true;

// Update is called once per frame
void LateUpdate () {

if((EnemyAI.flipface == false) && !facingRight){
Flip();
}
else if((EnemyAI.flipface == true) && facingRight){
Flip();
}
}
private void Flip()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;

// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}

No comments:

Post a Comment