Unity/수업내용
                
              Unity 21.04.06.수업내용
                HappyFrog
                 2021. 4. 6. 18:21
              
                          
            프리팹(PreFab)은 게임오브젝트가 'file화' 된 것.
Rigidbody : 물리적 작용
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ClearDirector : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            SceneManager.LoadScene("GameScene");
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
    GameObject cat;
    // Start is called before the first frame update
    void Start()
    {
        this.cat = GameObject.Find("cat");
    }
    // Update is called once per frame
    void Update()
    {
        Vector3 playerPos = this.cat.transform.position;
        transform.position = new Vector3(transform.position.x, playerPos.y, transform.position.z);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
    
    Animator animator;
    Rigidbody2D rigid2D;
    public float jumpForce;
    public float walkForce;
    public float maxWalkSpeed;
    // Start is called before the first frame update
    void Start()
    {
        this.rigid2D = this.GetComponent<Rigidbody2D>();
        this.animator = GetComponent<Animator>();
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            this.rigid2D.AddForce(transform.up * this.jumpForce);
        }
        var dir = 0;
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            dir = -1;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            dir = 1;
        }
        float speedx = Mathf.Abs(this.rigid2D.velocity.x);
        if(speedx < 2.0f)
        {
            this.rigid2D.AddForce(this.transform.right * dir * walkForce);
        }
        if(dir != 0)
        {
            transform.localScale = new Vector3(dir, 1, 1);
        }
        this.animator.speed = speedx / 2.0f;
        
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("WIN !");
        SceneManager.LoadScene("ClearScene");
    }
}

============================================================================