58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/* Minimális logika, hogy az animált emberek megfelelően változtassanak irányt.
|
|
* A prefabs mappában található megfelelő prefab lerakásával lehet 90°-os fordulásra bíztatni az embereket.
|
|
* Az előbbit lassan, szép átmenettel csinálja. Tud 180°-ot is fordulni, azt ugrásszerűen végzi.
|
|
*/
|
|
|
|
public class peopleTurning : MonoBehaviour {
|
|
|
|
public float turningSpeed = 0.1f;
|
|
|
|
private float turningSpeedWithDirection;
|
|
private bool isTurning = false;
|
|
public float currentAngle;
|
|
public float endAngle;
|
|
|
|
void FixedUpdate () {
|
|
if(isTurning)
|
|
{
|
|
currentAngle += turningSpeedWithDirection * Time.deltaTime;
|
|
transform.rotation = Quaternion.AngleAxis(currentAngle, transform.up);
|
|
|
|
if (Mathf.Abs(currentAngle % 360 - endAngle) < 10)
|
|
{
|
|
transform.rotation = Quaternion.AngleAxis(endAngle, transform.up);
|
|
isTurning = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter (Collider other)
|
|
{
|
|
if (!isTurning)
|
|
{
|
|
if (other.tag == "peopleTurnRight")
|
|
{
|
|
isTurning = true;
|
|
currentAngle = transform.rotation.eulerAngles.y;
|
|
endAngle = currentAngle + 90;
|
|
turningSpeedWithDirection = turningSpeed;
|
|
}
|
|
else if (other.tag == "peopleTurnLeft")
|
|
{
|
|
isTurning = true;
|
|
currentAngle = transform.rotation.eulerAngles.y;
|
|
endAngle = currentAngle - 90;
|
|
turningSpeedWithDirection = -turningSpeed;
|
|
}
|
|
}
|
|
|
|
if (other.tag == "peopleTurnAround")
|
|
{
|
|
transform.rotation = Quaternion.AngleAxis(transform.rotation.eulerAngles.y + 180, transform.up);
|
|
}
|
|
}
|
|
}
|