ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 코딩 메모/ 이번회차는 메인 캐릭터에만 메모
    코딩메모 2022. 9. 21. 20:41
    반응형

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class rtan : MonoBehaviour
    {
        float direction = 0.05f;
        float toward = 1.0f;

        // Start is called before the first frame update
        void Start()
        {
            
        }

        // Update is called once per frame
        void Update()
        {
            //Debug.Log(transform.position.x);//디버깅용 코드 디버그 후엔 삭제해도 무관

            if (Input.GetMouseButtonDown(0))
            {
                toward *= -1; 
                direction *= -1;
            }
            if (transform.position.x > 2.8f)//만약 오브젝트의 포지션 x값이 2.8float 보다 크다면
                {
                direction = -0.05f; // direction 이동값이 -0.05float(반대로) 변경
                toward = -1.0f;
            }
            if(transform.position.x < -2.8f)//만약 오브젝트의 포지션 x값이 -2.8float 보다 작다면
            {
                direction = 0.05f; // direction 이동값이 0.05float(반대로) 변경
                toward = 1.0f;
            }
            transform.localScale = new Vector3(toward, 1, 1);
            transform.position += new Vector3(direction, 0, 0); // 캐릭터의 위치 변경 요청 +값으로 (direction, 0, 0)만큼 이동

            
        }
    }


    // += 은 왼쪽값에 오른쪽 값을 더하라는뜻 *는 곱하라는뜻
    // 조건문은 "조건문(중괄호 안에있는것) 을 실행하는것"

     

     

     

    ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

     

    *강의들으면서 전체 코딩에 주석을 달아놓는게 좋을듯

    반응형

    '코딩메모' 카테고리의 다른 글

    팀 스파르타 4주차 코딩메모  (0) 2022.09.30
    팀 스파르타 3주차 코딩메모  (0) 2022.09.27
    팀 스파르타 2주차 코딩메모  (1) 2022.09.23
Designed by Tistory.