오늘 할일
오전
깃발. UI
오후
ui, 효과음.
1. 깃발 효과 주기
마리오가 깃발 몸통과 부딪히면 깃발 내려오기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlagController : MonoBehaviour
{
[SerializeField]
private GameObject flagGo;
private float moveSpeed = 2f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.tag == "mario"){
flagGo.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
if (flagGo.transform.position.y < -6.2)
{
this.moveSpeed = 0f;
}
}
}
}
봉에 마리오가 부딪히면 깃발과 마리오를 같이 아래로 이동
깃발은 y 값이 0.391와 같거나 작아지면 멈추고
handle 은 y 값이 0.618와 같거나 작아지면 멈춘다
다멈추면 로그를 찍는다 "complete!"
폭죽을 터트린다
onTriggerEnter를 하니까 한번 들어갈때마다 깃발이 조금씩 내려옴 ,마리오가 매달려있다가 떨어져버림 뭔가 잘못생각하고 있는거같음
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class FlagController : MonoBehaviour
{
[SerializeField]
private GameObject flagGo;
private float moveSpeed = 3f;
[SerializeField]
private Transform handle;
private MarioController marioController;
private bool isInFlag = false;
// Start is called before the first frame update
void Start()
{
isInFlag = false;
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "mario")
{
isInFlag = true;
if (isInFlag == true)
{
Debug.Log("마리오 들어왔습니다");
flagGo.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
if (flagGo.transform.position.y < 0.391f)
{
this.moveSpeed = 0f;
}
this.MarioTransMove();
Debug.Log("폭죽을 터뜨린다.");
isInFlag = false;
}
}
}
private void MarioTransMove()
{
GameObject mario = GameObject.Find("Mario");
Rigidbody2D mRigid =mario.GetComponent<Rigidbody2D>();
mario.transform.SetParent(this.handle);
mario.transform.position = handle.transform.position;
handle.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
mRigid.isKinematic = true;
mRigid.gravityScale = 0;
if (handle.transform.position.y <= 0.618f)
{
this.moveSpeed = 0f;
}
isInFlag = false;
Debug.LogError("!");
}
}
두번 호출됨 => 이유 하나의 오브젝트에 두개의 collider를 사용하면 is trigger가 체크되어있지 않은 collider에도 호출이 된다고 한다.
마리오가 자꾸 떨어짐 -> key입력을 계속 받아서 그럼 key 입력 못받게 하기
애니메이션 + 점프한 위치로 handle을 이동시킨다.
//마리오 위치
handle.transform.position = new Vector3(handle.transform.position.x, mario.transform.position.y, handle.transform.position.z);
//처음 위치 설정
mario.transform.position = handle.transform.position;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class FlagController : MonoBehaviour
{
[SerializeField]
private GameObject flagGo;
[SerializeField]
private float moveSpeed = 0.5f;
[SerializeField]
private Transform handle;
private MarioController marioController;
private bool isInFlag = false;
private bool canKey = true;
// Start is called before the first frame update
void Start()
{
isInFlag = false;
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log(collision.tag);
if (collision.CompareTag("mario"))
{
MarioController mario = GameObject.Find("Mario").GetComponent<MarioController>();
//마리오는 더이상 인풋을 받지 못함
mario.IgnoreInput(true);
Rigidbody2D mRigid = mario.GetComponent<Rigidbody2D>();
//현재 속도를 0으로 만듬
mRigid.velocity = Vector3.zero;
mRigid.angularVelocity = 0;
//부모를 핸들로 설정
mario.transform.SetParent(this.handle);
//물리 영향을 안받게 설정
mRigid.isKinematic = true;
//마리오 위치
handle.transform.position = new Vector3(handle.transform.position.x, mario.transform.position.y, handle.transform.position.z);
//처음 위치 설정
mario.transform.position = handle.transform.position;
//핸들 이동하기
this.StartCoroutine(this.CoMoveHandle());
this.StartCoroutine(this.CoMoveFlag());
}
//isInFlag = true;
//while (isInFlag)
//{
// flagGo.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
// if (flagGo.transform.position.y <= 0.391f)
// {
// this.moveSpeed = 0f;
// }
// Debug.Log("마리오 들어왔습니다");
// Debug.Log("폭죽을 터뜨린다.");
// isInFlag = false;
//}
}
private IEnumerator CoMoveFlag()
{
while (true)
{
flagGo.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
if (flagGo.transform.localPosition.y <= 0.391f)
{
this.moveSpeed = 0f;
break;
}
yield return null;
}
Debug.LogFormat("깃발이 이동을 완료 했습니다.");
}
private IEnumerator CoMoveHandle()
{
while (true)
{
handle.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
if (handle.transform.localPosition.y <= 0.63f)
{
this.moveSpeed = 0f;
break;
}
yield return null;
}
Debug.LogFormat("handle이 이동을 완료 했습니다.");
}
//private void MarioTransMove()
//{
// GameObject mario = GameObject.Find("Mario");
// Rigidbody2D mRigid =mario.GetComponent<Rigidbody2D>();
// mario.transform.SetParent(this.handle);
// mRigid.isKinematic = true;
// mario.transform.position = handle.transform.position;
// handle.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
// if (handle.transform.position.y <= 0.618f)
// {
// this.moveSpeed = 0f;
// }
// isInFlag = false;
// Debug.Log("움직인다");
//}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using Unity.VisualScripting.Antlr3.Runtime.Tree;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MarioController : MonoBehaviour
{
private Rigidbody2D rBody2D;
public float jumpForce = 500f;
public float moveForce = 60f;
private Animator anim;
private bool isJump = false;
private bool isLongJump = false;
//[SerializeField]
//private UIDirector uiDirector;
[SerializeField]
private Transform rayOrigin; //체크 아래쪽 하기 위한 레이 발사 시작 위치
//private float scaleChange = 0;
public System.Action<float> onGetMushroom; //대리자 변수 정의
public System.Action<float> onAttackedEnemy;
public System.Action<string> onChangeScene;
public System.Action onCoinEat;
// Start is called before the first frame update
void Start()
{
this.rBody2D = this.GetComponent<Rigidbody2D>();
this.anim = this.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
//인풋이 막인 상태에서는 아무것도 못하게 막음
if (this.ignoreInput) return;
//jump
if (Input.GetKeyDown(KeyCode.Space))
{
// 이중점프 막기
if (this.rBody2D.velocity.y == 0)
{
this.rBody2D.AddForce(Vector2.up * this.jumpForce);
if (this.isJump == false)
{
this.isJump = true;
}
}
}
if (this.isJump)
{
if (this.rBody2D.velocity.y > 0)
{
// Jumping
this.anim.SetBool("isJump", true);
}
else if (this.rBody2D.velocity.y <= 0)
{
// Falling
this.anim.SetBool("isJump", false);
}
}
//if (Input.GetButtonUp("Horizontal"))
//{
// this.rBody2D.velocity = new Vector2(this.rBody2D.velocity.normalized.x * 0.8f, this.rBody2D.velocity.y);
//}
//if (this.isJump)// space를 눌렀는데
//{
//if (this.rBody2D.velocity.y > 0)// 점프상태
//{
// this.anim.SetInteger("State", 2);
//}
//}
int dirX = 0;
if (Input.GetKey(KeyCode.LeftArrow))
{
dirX = -1;
}
if (Input.GetKey(KeyCode.RightArrow))
{
dirX = 1;
}
float speedX = Mathf.Abs(this.rBody2D.velocity.x);//절대값(속도는 음수 나오면 안됨), 가속도
if (speedX < 5f)//가속도 제한
{
this.rBody2D.AddForce(new Vector2(dirX, 0) * this.moveForce);
}
//움직이는 방향으로 쳐다보기
if (dirX != 0)//달리고 있다면?
{
//if (!this.isJump)//좌우를 쳐다보는데 점프 상태가 아니라면 => 걷는중
//{
this.anim.SetInteger("State", 1);
this.anim.SetBool("isJump", false);
//}
this.transform.localScale = new Vector3(dirX *Mathf.Abs(this.transform.localScale.x), this.transform.localScale.y, 1);
this.transform.position = new Vector3(Mathf.Clamp(this.transform.position.x, -8.1f, 25.9f),this.transform.position.y, 0);
}
else//좌우를 쳐다보지도 않고 점프 상태도 아니라면 =>idle
{
if (this.isJump==false)
{
this.anim.SetInteger("State", 0);
this.anim.SetBool("isJump", false);
}
}
this.anim.speed = speedX / 2.0f;
//길게 누르면 높은 점프 짧게 누르면 낮은 점프
if (Input.GetKey(KeyCode.Space))
{
isLongJump = true;
}
else if (Input.GetKeyUp(KeyCode.Space))
{
isLongJump = false;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("아래 들어갈때가 있는지 확인한다");
this.CheckPortalBelow();
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
this.CheckPortalRight();
}
}
private Coroutine routineCheckPortalBelow;
private Coroutine routineCheckPortalRight;
private void CheckPortalBelow()
{
if (this.routineCheckPortalBelow != null) StopCoroutine(this.routineCheckPortalBelow);
this.routineCheckPortalBelow = this.StartCoroutine(this.CoCheckPortalBelow());
}
private void CheckPortalRight()
{
if (this.routineCheckPortalRight != null) StopCoroutine(this.routineCheckPortalRight);
this.routineCheckPortalRight = this.StartCoroutine(this.CoCheckPortalRight());
}
private IEnumerator CoCheckPortalBelow()
{
yield return null;
//레이를 만듬
Ray ray = new Ray(this.rayOrigin.transform.position, this.transform.up * -1);//this.transform.up*-1 = 아래로 레이만들기
Debug.DrawRay(ray.origin, ray.direction, Color.red, 10f);
LayerMask mask = 1 << LayerMask.NameToLayer("Mario");//마리오Layer만(6)
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 1, ~mask);//~mask= 마리오 빼고 다
if (hit)
{
Debug.Log(hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "portal2")
{
Debug.Log("씬2로 전환");
this.onChangeScene("Map2Scene");
}
}
}
private IEnumerator CoCheckPortalRight()
{
yield return null;
Ray ray2 = new Ray(this.rayOrigin.transform.position, this.transform.right * -1);
Debug.DrawRay(ray2.origin, ray2.direction, Color.green, 10f);
LayerMask mask = 1 << LayerMask.NameToLayer("Mario");//마리오Layer만(6)
RaycastHit2D hit2 = Physics2D.Raycast(ray2.origin, ray2.direction, 1, ~mask);
if (hit2)
{
Debug.Log(hit2.collider.gameObject.name);
if (hit2.collider.gameObject.name == "portal3")
{
Debug.Log("씬3으로전환");
this.onChangeScene("Map3Scene");
}
}
}
private void FixedUpdate()
{
//인풋이 막인 상태에서는 아무것도 안함
if (this.ignoreInput) return;
if (isLongJump && this.rBody2D.velocity.y > 0)
{
this.rBody2D.gravityScale = 1.2f;
}
else
{
this.rBody2D.gravityScale = 2.5f;
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "coin")
{
Destroy(other.gameObject);
this.onCoinEat();
}
else if (other.gameObject.tag == "flag")
{
this.anim.SetInteger("State", 3);
//this.uiDirector.IncreaseScore(400);
}
else if (other.gameObject.tag == "castle")
{
//this.uiDirector.time = 0;
//Time.timeScale = 0.5f;
//코루틴 하면 좋을거같음
SceneManager.LoadScene("GameOverScene");
}
//this.uiDirector.UpdateUI();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "mushroom")
{
Destroy(collision.gameObject); //버섯 제거
this.onGetMushroom(0.6f); //대리자 호출
}
//if (isSmall == false)
//{
if (collision.gameObject.tag == "enemy")
{
//if (this.transform.localScale.x == 0.4f)
//{
// SceneManager.LoadScene("GameOverScene");
//}
this.onAttackedEnemy(0.4f);
}
//}
}
public void Bigger(float scale)
{
if (this.IsBig)
{
Debug.Log("이미 커진 상태 입니다.");
}
else //작은 상태면 크기증가
{
this.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
this.IsBig = true;
}
}
public void Smaller(float scale)
{
if (this.IsSmall)
{
Debug.Log("이미 작아진 상태 입니다.");
}
else
{
this.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
this.IsSmall = true;
this.IsBig = false;
}
}
private bool ignoreInput = false;
public void IgnoreInput(bool ignore)
{
ignoreInput = ignore;
Debug.LogFormat("IgnoreInput: <color=lime>{0}</color>", this.ignoreInput);
}
public bool IsBig//true,false
{
get; set;
}
public bool IsSmall
{
get;set;
}
}
문제는 키 입력을 못받게 해놔서 그 다음에 성으로 움직일수가 없음
집가서 할거
그냥 깃발 도착하면 폭죽 터트리고 gameover 씬 나오게 하기
거북이 누르면 사라지기
ui json 저장하기
효과음 주기
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
public class FlagController : MonoBehaviour
{
[SerializeField]
private GameObject flagGo;
[SerializeField]
private float moveSpeed = 0.5f;
[SerializeField]
private Transform handle;
private MarioController marioController;
private bool isInFlag = false;
private bool canKey = true;
// Start is called before the first frame update
void Start()
{
isInFlag = false;
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log(collision.tag);
if (collision.CompareTag("mario"))
{
MarioController mario = GameObject.Find("Mario").GetComponent<MarioController>();
//마리오는 더이상 인풋을 받지 못함
mario.IgnoreInput(true);
Rigidbody2D mRigid = mario.GetComponent<Rigidbody2D>();
//현재 속도를 0으로 만듬
mRigid.velocity = Vector3.zero;
mRigid.angularVelocity = 0;
//부모를 핸들로 설정
mario.transform.SetParent(this.handle);
//물리 영향을 안받게 설정
mRigid.isKinematic = true;
//마리오 위치
handle.transform.position = new Vector3(handle.transform.position.x, mario.transform.position.y, handle.transform.position.z);
//처음 위치 설정
mario.transform.position = handle.transform.position;
//핸들 이동하기
this.StartCoroutine(this.CoMoveHandle());
this.StartCoroutine(this.CoMoveFlag());
this.StartCoroutine(this.CoLoadGameOver());
// mario.IgnoreInput(false);
}
//isInFlag = true;
//while (isInFlag)
//{
// flagGo.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
// if (flagGo.transform.position.y <= 0.391f)
// {
// this.moveSpeed = 0f;
// }
// Debug.Log("마리오 들어왔습니다");
// Debug.Log("폭죽을 터뜨린다.");
// isInFlag = false;
//}
}
private IEnumerator CoMoveFlag()
{
while (true)
{
flagGo.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
if (flagGo.transform.localPosition.y <= 0.391f)
{
this.moveSpeed = 0f;
break;
}
yield return null;
}
Debug.LogFormat("깃발이 이동을 완료 했습니다.");
}
private IEnumerator CoLoadGameOver()
{
yield return new WaitForSeconds(3f);
SceneManager.LoadScene("GameOverScene");
}
private IEnumerator CoMoveHandle()
{
while (true)
{
handle.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
if (handle.transform.localPosition.y <= 0.63f)
{
this.moveSpeed = 0f;
break;
}
yield return null;
}
Debug.LogFormat("handle이 이동을 완료 했습니다.");
}
//private void MarioTransMove()
//{
// GameObject mario = GameObject.Find("Mario");
// Rigidbody2D mRigid =mario.GetComponent<Rigidbody2D>();
// mario.transform.SetParent(this.handle);
// mRigid.isKinematic = true;
// mario.transform.position = handle.transform.position;
// handle.transform.Translate(this.moveSpeed * Vector3.down * Time.deltaTime);
// if (handle.transform.position.y <= 0.618f)
// {
// this.moveSpeed = 0f;
// }
// isInFlag = false;
// Debug.Log("움직인다");
//}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using Unity.VisualScripting.Antlr3.Runtime.Tree;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MarioController : MonoBehaviour
{
private Rigidbody2D rBody2D;
public float jumpForce = 500f;
public float moveForce = 60f;
private Animator anim;
private bool isJump = false;
private bool isLongJump = false;
//[SerializeField]
//private UIDirector uiDirector;
[SerializeField]
private Transform rayOrigin; //체크 아래쪽 하기 위한 레이 발사 시작 위치
//private float scaleChange = 0;
public System.Action<float> onGetMushroom; //대리자 변수 정의
public System.Action<float> onAttackedEnemy;
public System.Action<string> onChangeScene;
public System.Action onCoinEat;
// Start is called before the first frame update
void Start()
{
this.rBody2D = this.GetComponent<Rigidbody2D>();
this.anim = this.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
//인풋이 막인 상태에서는 아무것도 못하게 막음
if (this.ignoreInput) return;
//jump
if (Input.GetKeyDown(KeyCode.Space))
{
// 이중점프 막기
if (this.rBody2D.velocity.y == 0)
{
this.rBody2D.AddForce(Vector2.up * this.jumpForce);
if (this.isJump == false)
{
this.isJump = true;
}
}
}
if (this.isJump)
{
if (this.rBody2D.velocity.y > 0)
{
// Jumping
this.anim.SetBool("isJump", true);
}
else if (this.rBody2D.velocity.y <= 0)
{
// Falling
this.anim.SetBool("isJump", false);
}
}
//if (Input.GetButtonUp("Horizontal"))
//{
// this.rBody2D.velocity = new Vector2(this.rBody2D.velocity.normalized.x * 0.8f, this.rBody2D.velocity.y);
//}
//if (this.isJump)// space를 눌렀는데
//{
//if (this.rBody2D.velocity.y > 0)// 점프상태
//{
// this.anim.SetInteger("State", 2);
//}
//}
int dirX = 0;
if (Input.GetKey(KeyCode.LeftArrow))
{
dirX = -1;
}
if (Input.GetKey(KeyCode.RightArrow))
{
dirX = 1;
}
float speedX = Mathf.Abs(this.rBody2D.velocity.x);//절대값(속도는 음수 나오면 안됨), 가속도
if (speedX < 5f)//가속도 제한
{
this.rBody2D.AddForce(new Vector2(dirX, 0) * this.moveForce);
}
//움직이는 방향으로 쳐다보기
if (dirX != 0)//달리고 있다면?
{
//if (!this.isJump)//좌우를 쳐다보는데 점프 상태가 아니라면 => 걷는중
//{
this.anim.SetInteger("State", 1);
this.anim.SetBool("isJump", false);
//}
this.transform.localScale = new Vector3(dirX *Mathf.Abs(this.transform.localScale.x), this.transform.localScale.y, 1);
this.transform.position = new Vector3(Mathf.Clamp(this.transform.position.x, -8.1f, 25.9f),this.transform.position.y, 0);
}
else//좌우를 쳐다보지도 않고 점프 상태도 아니라면 =>idle
{
if (this.isJump==false)
{
this.anim.SetInteger("State", 0);
this.anim.SetBool("isJump", false);
}
}
this.anim.speed = speedX / 2.0f;
//길게 누르면 높은 점프 짧게 누르면 낮은 점프
if (Input.GetKey(KeyCode.Space))
{
isLongJump = true;
}
else if (Input.GetKeyUp(KeyCode.Space))
{
isLongJump = false;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("아래 들어갈때가 있는지 확인한다");
this.CheckPortalBelow();
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
this.CheckPortalRight();
}
}
private Coroutine routineCheckPortalBelow;
private Coroutine routineCheckPortalRight;
private void CheckPortalBelow()
{
if (this.routineCheckPortalBelow != null) StopCoroutine(this.routineCheckPortalBelow);
this.routineCheckPortalBelow = this.StartCoroutine(this.CoCheckPortalBelow());
}
private void CheckPortalRight()
{
if (this.routineCheckPortalRight != null) StopCoroutine(this.routineCheckPortalRight);
this.routineCheckPortalRight = this.StartCoroutine(this.CoCheckPortalRight());
}
private IEnumerator CoCheckPortalBelow()
{
yield return null;
//레이를 만듬
Ray ray = new Ray(this.rayOrigin.transform.position, this.transform.up * -1);//this.transform.up*-1 = 아래로 레이만들기
Debug.DrawRay(ray.origin, ray.direction, Color.red, 10f);
LayerMask mask = 1 << LayerMask.NameToLayer("Mario");//마리오Layer만(6)
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 1, ~mask);//~mask= 마리오 빼고 다
if (hit)
{
Debug.Log(hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "portal2")
{
Debug.Log("씬2로 전환");
this.onChangeScene("Map2Scene");
}
}
}
private IEnumerator CoCheckPortalRight()
{
yield return null;
Ray ray2 = new Ray(this.rayOrigin.transform.position, this.transform.right * -1);
Debug.DrawRay(ray2.origin, ray2.direction, Color.green, 10f);
LayerMask mask = 1 << LayerMask.NameToLayer("Mario");//마리오Layer만(6)
RaycastHit2D hit2 = Physics2D.Raycast(ray2.origin, ray2.direction, 1, ~mask);
if (hit2)
{
Debug.Log(hit2.collider.gameObject.name);
if (hit2.collider.gameObject.name == "portal3")
{
Debug.Log("씬3으로전환");
this.onChangeScene("Map3Scene");
}
}
}
private void FixedUpdate()
{
//인풋이 막인 상태에서는 아무것도 안함
if (this.ignoreInput) return;
if (isLongJump && this.rBody2D.velocity.y > 0)
{
this.rBody2D.gravityScale = 1.2f;
}
else
{
this.rBody2D.gravityScale = 2.5f;
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.gameObject.tag == "flag")
{
this.anim.SetInteger("State", 3);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "coin")
{
Destroy(other.gameObject);
this.onCoinEat();
}
//this.uiDirector.IncreaseScore(400);
//this.uiDirector.UpdateUI();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "mushroom")
{
Destroy(collision.gameObject); //버섯 제거
this.onGetMushroom(0.6f); //대리자 호출
}
//if (isSmall == false)
//{
if (collision.gameObject.tag == "enemy")
{
//if (this.transform.localScale.x == 0.4f)
//{
// SceneManager.LoadScene("GameOverScene");
//}
//this.onAttackedEnemy(0.4f);
Destroy(collision.gameObject);
}
//}
}
public void Bigger(float scale)
{
if (this.IsBig)
{
Debug.Log("이미 커진 상태 입니다.");
}
else //작은 상태면 크기증가
{
this.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
this.IsBig = true;
}
}
public void Smaller(float scale)
{
if (this.IsSmall)
{
Debug.Log("이미 작아진 상태 입니다.");
}
else
{
this.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
this.IsSmall = true;
this.IsBig = false;
}
}
private bool ignoreInput = false;
public void IgnoreInput(bool ignore)
{
ignoreInput = ignore;
Debug.LogFormat("IgnoreInput: <color=lime>{0}</color>", this.ignoreInput);
}
public bool IsBig//true,false
{
get; set;
}
public bool IsSmall
{
get;set;
}
}
오디오 사운드 집어넣기
AudioSource.PlayOneShot does not cancel clips that are already being played by AudioSource.PlayOneShot and AudioSource.Play. = PlayOneShot을 해야 다른 오디오를 취소시키지 않고 여러 사운드가 중첩되게 나옴, 슈퍼마리오의 경우는 중첩되게 나와야하므로 PlayOneShot을 사용했다.
'2D 콘텐츠 제작 개발일지 (mario)' 카테고리의 다른 글
유니티(unity) 씬 전환 시 UI 유지하기 (2) | 2024.09.25 |
---|---|
슈퍼마리오 전체코드 (1) | 2023.09.21 |
마리오 개발 7일차 (2) | 2023.09.19 |
마리오 개발 6일차 (0) | 2023.09.18 |
마리오개발 5일차 (0) | 2023.09.17 |