using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBall : MonoBehaviour
{
public float jumpPower = 10;
bool isJump;
Rigidbody rigid;
public int itemCount;
AudioSource audioS;
// Start is called before the first frame update
void Awake()
{
isJump = false;
rigid = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetButtonDown("Jump") && !isJump)
{
isJump = true;
rigid.AddForce(new Vector3(0, jumpPower, 0), ForceMode.Impulse);
}
}
// Update is called once per frame
void FixedUpdate()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
rigid.AddForce(new Vector3(h, 0, v), ForceMode.Impulse);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Floor")
{ isJump = false; }
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "ITEM"){
itemCount++;
audioS.Play();
other.gameObject.SetActive(false);
}
}
}
OnTriggerEnter ๋ง์ง๋ง ์ฝ๋. ์์ดํ ๋จน์ผ๋ฉด ์๋ฆฌ๋์ค๋ฉด์ ์ฌ๋ผ์ง๊ณ itemCount 1์ฌ๋ฆฌ๋ ๋ถ๋ถ์ด ์์ ์๋์ ์ํ๋ค์.
์คํฌ๋ฆฝํธ ์ค๋ฅ๋ ์๋๋ฐ. ๋ช๋ฒ์ ํ์ธํด๋ ๋ญ๊ฐ ์๋ชป๋๊ฑด์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
tag๋ ITEM์ผ๋ก ํ์์ต๋๋ค.
์๋ ค์ฃผ์ค๋ถ?
it(other.compareTag("Item")
๊ทธ๋ฆฌ๊ณ ์ถฉ๋ํ ์ค๋ธ์ ํธ ์ค ํ๋๋ผ๋ trigger๋ฅผ ์ผ๋์๋์ง ํ์ธ
์ด๊ฑด ์๋๋ฏ์.. ๋ฐ๋ก ์ค๋ฅ ๋จ๋ค์..
๋ณต๋ถํ์ง๋ง๊ณ ์๋ผ์ผ
ํธ๋ฆฌ๊ฑฐ๊ฐ ์ ์ผ์ ธ์์๋ค์! ๊ฐ์ฌํฉ๋๋ค!
๋์ค์ ํ๋๋ผ๋ ๋ฆฌ์ง๋ ๋ฐ๋.์์ด์ผ๋๋ค - dc App
audioS๊ฐ private์ธ๋ ํ ๋นํ๋ ๋ถ๋ถ๋์๊ณ ์คํ์๋๋๊ฒ ๋น์ฐํ๊ฑฐ์๋๋