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์œผ๋กœ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


์•Œ๋ ค์ฃผ์‹ค๋ถ„?