아카이브

유니티짱 직선으로 움직이기 본문

유니티 기초

유니티짱 직선으로 움직이기

timbercat 2023. 8. 4. 16:41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class YukoController : MonoBehaviour
{
    private float moveSpeed = 0.5f;
    private Animator anim;
    private bool isMove = false;
    
    // Start is called before the first frame update
    void Start()
    {
        this.anim = this.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (isMove)
        {
            if(this.transform.position.z >= 5)
            {
                //stop
                this.anim.SetInteger("State", 0);
                this.isMove = false;
            }
            else
            {
                this.transform.Translate(Vector3.forward * this.moveSpeed * Time.deltaTime);
                Debug.Log(this.transform.position);
                this.anim.SetInteger("State", 1);
            }
        }
    }

    public void MoveStart()
    {
        Debug.Log("Move Start!");       
        this.isMove = true;
    }
}

'유니티 기초' 카테고리의 다른 글

아이템 착용하기  (0) 2023.08.11
클릭한 위치에 몬스터 생성/삭제  (0) 2023.08.10
주말과제(Dog Knight)  (1) 2023.08.06
8/1 유니티 복습  (0) 2023.08.02
7/31 유니티 복습  (0) 2023.07.31