유니티 기초
유니티 애니메이션 & 직선 이동 및 대각선 이동
EasyCastleT
2023. 8. 4. 16:14
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MisakiController : MonoBehaviour
{
Animator anim;
public float moveSpeed = 10.0f;
public int state;
public Transform target;
// Start is called before the first frame update
void Start()
{
this.anim = this.GetComponent<Animator>();
this.state = 0;
}
// Update is called once per frame
void Update()
{
this.transform.LookAt(this.target);
Debug.Log(state);
if (state == 1)
{
this.StartRun();
}
if (this.transform.position.z > 3)
{
Debug.Log("Misaki Stand");
this.moveSpeed = 0;
this.state = 0;
this.anim.SetInteger("Run", state);
}
else
{
Debug.Log("Misaki Run");
//state = true;
}
}
public void StartRun()
{
// this.transform.Translate(this.moveSpeed * Time.deltaTime, 0, this.moveSpeed * Time.deltaTime);
this.transform.Translate(Vector3.forward * this.moveSpeed * Time.deltaTime);
}
public void StateChange()
{
if (state == 1) //1이면 Run
{
this.state = 0;
this.anim.SetInteger("Run", state);
}
else if (state == 0) //0이면 Stand
{
state = 1;
this.anim.SetInteger("Run", state);
}
}
}
LookAt -> 오브젝트가 target이 된 오브젝트를 바라보게 함