using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Assertions.Comparers;
using UnityEngine.SceneManagement;
public class CatController : MonoBehaviour
{
[SerializeField] private Rigidbody2D rbody;
[SerializeField] private float moveForce = 100f;
[SerializeField] private float jumpForce = 680f;
[SerializeField]
private ClimbCloudGameDirector gameDirector;
private Animator anim;
private bool hasSpace = false;
private void Start()
{
//this.gameObject.GetComponent<Animation>();
anim = GetComponent<Animator>();
//this.gameDirector = GameObject.Find("GameDirector").GetComponent<ClimbCloudGameDirector>();
//this.gameDirector = GameObject.FindAnyObjectByType<ClimbCloudGameDirector>();
}
void Update()
{
//스페이스바를 누르면
if (Mathf.Abs(rbody.velocity.y) < 0.01f)
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (!hasSpace)
{
//힘을 가한다
this.rbody.AddForce(this.transform.up * this.jumpForce);
//this.rbody.AddForce(Vector3.up * this.force);
hasSpace = false; // 다시 점프할 수 있도록 허용
}
}
}
// -1, 0, 1 : 방향
int dirX = 0;
//왼쪽화살표키를 누르고 있는 동안에
if (Input.GetKey(KeyCode.LeftArrow))
{
dirX = -1;
}
if (Input.GetKey(KeyCode.RightArrow))
{
dirX = 1;
}
// Debug.Log(dirX); //방향 -1, 0, 1
//스케일 X를 변경 하는데 키가 눌렸을 때만
//키가 눌렸을때만 = (dirX != 0)
if (dirX != 0)
{
this.transform.localScale = new Vector3(dirX, 1, 1);
}
//벡터의 곱
//Debug.Log(this.transform.right * dirX); //벡터3
//도전 ! : 속도를 제한하자
//velocity.x 가 3정도가 넘어가니깐 빨라지는거 같드라구...
if (Mathf.Abs(this.rbody.velocity.x) < 3)
{
this.rbody.AddForce(this.transform.right * dirX * moveForce);
}
this.anim.speed = (Mathf.Abs(this.rbody.velocity.x) / 2f);
this.gameDirector.UpdateVelocityText(this.rbody.velocity);
// Debug.Log(this.transform.position);
float clampX = Mathf.Clamp(this.transform.position.x, -2.39f, 2.35f);
Vector3 pos = this.transform.position;
pos.x = clampX;
this.transform.position = pos;
}
// Trigger 모드 일경우 충돌 판정을 해주는 이벤트 함수
private bool hasEntered = false;
private void OnTriggerEnter2D(Collider2D collision)
{
if (!hasEntered)
{
Debug.LogFormat("OnTriggerEnter2D: {0}", collision);
SceneManager.LoadScene("ClimbCloudClear");
hasEntered = true; // 한 번 이벤트가 발생하면 이 변수를 true로 설정하여 두 번 이상 호출되지 않도록 함
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
SceneManager.LoadScene("ClimbCloud");
Debug.Log("화면이 전환됨");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ClimbCloudGameDirector : MonoBehaviour
{
[SerializeField] private Text velocityText;
public void UpdateVelocityText(Vector2 velocity)
{
float velocityX = Mathf.Abs(velocity.x);
this.velocityText.text = velocityX.ToString();
}
}
콜라이더(Collider)컴포넌트는 물리 충돌 처리를 위한 오브젝트의 형태를 정의합니다. 콜라이더는 보이지 않는 요소이므로 오브젝트의 메시와 정확히 동일한 모양일 필요는 없으며, 실제로는 게임플레이 시에는 대략적인 근사치로도 크게 구분되지 않으며 더 효율적입니다.
가장 간단한(그리고 프로세서에 부하를 주지 않는) 콜라이더는기본콜라이더 타입입니다. 3D에서는박스 콜라이더,스피어 콜라이더,캡슐 콜라이더가 바로 이 타입입니다. 2D에서는박스 콜라이더 2D와써클 콜라이더 2D를 사용할 수 있습니다.복합 콜라이더를 만들기 위해 하나의 오브젝트에 위와 같은 콜라이더를 몇 개든 추가할 수 있습니다.