using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CatController : MonoBehaviour
{
private Rigidbody2D rBody2D;
public float jumpForce = 650f;
private float moveForce = 30f;
private Animator anim;
private int jumpCount=0;
private float yVelocity;
// Start is called before the first frame update
void Start()
{
this.rBody2D = this.GetComponent<Rigidbody2D>();
this.anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
yVelocity = rBody2D.velocity.y * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
if (yVelocity > 0)
{
}
else if (yVelocity == 0) {
this.rBody2D.AddForce(Vector2.up * this.jumpForce, ForceMode2D.Impulse);
this.jumpCount = 1;
}
}
int drX = 0;
if(Input.GetKey(KeyCode.LeftArrow))
{
drX = -1;
}
if (Input.GetKey(KeyCode.RightArrow))
{
drX = 1;
}
float speedX = Mathf.Abs(this.rBody2D.velocity.x);
if (speedX < 2f)
{
this.rBody2D.AddForce(new Vector2(drX, 0) * this.moveForce);
}
if(drX != 0)
{
this.transform.localScale = new Vector3(drX, 1, 1);
}
this.anim.speed = speedX / 2.0f;
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.LogFormat("{0}", collision.name);
Debug.LogFormat("Game Clear씬으로 전환!");
SceneManager.LoadScene("ClearScene");
}
private void OnTriggerExit2D(Collider2D collision)
{
Debug.LogFormat("{0}", collision.name);
}
//private void OnTriggerStay2D(Collider2D collision)
//{
// Debug.LogFormat("{0}", collision.name);
//}
}
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 FollowPlayer : MonoBehaviour
{
private GameObject catGo;
Vector3 position;
// Start is called before the first frame update
void Start()
{
this.catGo = GameObject.Find("cat");
}
// Update is called once per frame
void Update()
{
if(catGo.transform.position.y>0)
transform.position = new Vector3(0,catGo.transform.position.y,-1);
}
}
'유니티 기초' 카테고리의 다른 글
유니티짱 마우스로 움직이기 (0) | 2023.08.04 |
---|---|
밤송이 던지기 (0) | 2023.08.04 |
유니티 애니메이션(점프) (0) | 2023.08.03 |
유니티 애니메이션 (0) | 2023.08.03 |
수리검 던지기 (0) | 2023.08.01 |