์ด๊ฑฐ Shoot์์ ๋ฌธ์ ์๊ธด๊ฑฐ ๊ฐ์์ ๋ชจ๋
ธ๋นํค์ด๋น์ด ์ง์ฐ๊ณ ๋ค์ ์ ์ด์ ์ ์ฅ ๋ฐ์๋๋ฐ ์ ๊ฑธ ์ฐธ์กฐ ๋ชปํ๋๋ฐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
using Unity.Mathematics;
public class Shoot : MonoBehaviour
{
public int[] magazine_;//Maxํ
public int[] magazine;//ํ์ฌํ
Animator animator;
public GameObject Hbullet;
public GameObject Rbullet;
SpriteRenderer spriteRenderer;
Bullet m_bullet;
public Rigidbody2D bulletInstance;
public int[] BulletCount;//์ ์ฅ์ ๋๋ ํํ์
public int maxSpeed = 5;
public Button btn;
public Text BulletText;
public Text Clip;
// Start is called before the first frame update
public AudioClip[] GunSound;
public int WeaPonType = 1;
public GameObject[] Image;
public Text MedikitCT;
Health Medi;
private void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
Medi = GetComponent<Health>();
}
void Start()
{
BulletText.text = "X " + magazine_[WeaPonType];
Clip.text = "X " + magazine[WeaPonType]/ (int)BulletCount[WeaPonType];
MedikitCT.text = "X " + Medi.MedikitCount;
}
// Update is called once per frame
void Update()
{
if (magazine_[WeaPonType] == 0 && BulletCount[WeaPonType] == 0)
{
}
else if (magazine_[WeaPonType] == 0 && BulletCount[WeaPonType] >= 1)
{
Reload();
}
WriteText();
}
public void OnButton_()
{
if (WeaPonType == 0)//ํจ๋๊ฑด
{
if (magazine_[0] > 0)
{
magazine_[0]--;
animator.SetTrigger("IsFire");
btn.interactable = false;
Debug.Log("Button was pressed!");
}
else
{
}
Invoke("StopFireAni", 0.5f);
}
else if (WeaPonType == 1)//๋ผ์ดํ
{
if (magazine_[1] > 0)
{
magazine_[1]--;
animator.SetTrigger("IsFire");
// SoundManager.Instance.RandomSoundEffect(AttackNoises);
btn.interactable = false;
Debug.Log("Button was pressed!");
if (spriteRenderer.flipX == false)
{
//Debug.Log("์ผ์ชฝ์ ๋ฐ๋ผ๋ณด๊ณ ์ด์จ์!");
//GameObject obj = Instantiate(Rbullet, new Vector3(transform.position.x + 0.3f, transform.position.y + 0.4f, transform.position.z), transform.rotation);
//Debug.Log("L_Player" + transform.forward + "L_Bullet" + obj.transform.forward + "Euler ๋ณํ ํ " + quaternion.Euler(transform.forward));
//obj.transform.name = "RBullet";
}
else if (spriteRenderer.flipX == true)
{
//Debug.Log("์ค๋ฅธ์ชฝ์ ๋ฐ๋ผ๋ณด๊ณ ์ด์จ์!");
//GameObject obj = Instantiate(Rbullet, new Vector3(transform.position.x + 0.3f, transform.position.y + 0.4f, transform.position.z), transform.rotation);
//Debug.Log("R_Player" + -transform.forward + "R_Bullet" + -obj.transform.forward + "Euler ๋ณํ ํ " + quaternion.Euler(-transform.forward));
//obj.transform.name = "RBullet";
}
}
else
{
}
//BulletText.text = "X " + magazine_;//+ "/" + BulletCount + "
Invoke("StopFireAni", 0.5f);
}
}
void Bulletboom()
{
Debug.Log("!");
}
void StopFireAni()
{
if (magazine_[WeaPonType] > 0)
{
btn.interactable = true;
}
else
{
Invoke("Reload", 0.1f);
btn.interactable = false;
}
}
public void Reload()
{
if (BulletCount[WeaPonType] <= magazine[WeaPonType])
{
magazine_[WeaPonType] = BulletCount[WeaPonType];
BulletCount[WeaPonType] = 0;
}
else
{
BulletCount[WeaPonType] -= magazine[WeaPonType];
magazine_[WeaPonType] = magazine[WeaPonType];
}
btn.interactable = true;
}
void WriteText()
{
if (WeaPonType == 0)//1,3
{
Image[0].SetActive(false);
Image[2].SetActive(false);
Image[1].SetActive(true);
Image[3].SetActive(true);
}
else if (WeaPonType == 1)//0,2
{
Image[0].SetActive(true);
Image[2].SetActive(true);
Image[1].SetActive(false);
Image[3].SetActive(false);
}
BulletText.text = "X " + magazine_[WeaPonType];
Clip.text = "X " + (int)BulletCount[WeaPonType] / magazine[WeaPonType];
MedikitCT.text = "X " + Medi.MedikitCount;
}
public void BulletIns()
{
SoundManager.Instance.RandomSoundEffect(GunSound);
if (WeaPonType == 0)
{
if (spriteRenderer.flipX == false)
{
GameObject obj = Instantiate(Hbullet, new Vector3(transform.position.x - 1.8f, transform.position.y + 0.4f, transform.position.z), transform.rotation);
obj.transform.name = "HBullet";
}
else
{
GameObject obj = Instantiate(Hbullet, new Vector3(transform.position.x + 1.8f, transform.position.y + 0.4f, transform.position.z), transform.rotation);
obj.transform.name = "HBullet";
}
}
else if (WeaPonType == 1)
{
if (spriteRenderer.flipX == false)
{
GameObject obj = Instantiate(Rbullet, new Vector3(transform.position.x - 1.8f, transform.position.y + 0.4f, transform.position.z), transform.rotation);
obj.transform.name = "RBullet";
}
else
{
GameObject obj = Instantiate(Rbullet, new Vector3(transform.position.x + 1.8f, transform.position.y + 0.4f, transform.position.z), transform.rotation);
obj.transform.name = "RBullet";
}
}
}
}
๊ทธ๊ฑฐ ์ด๋ ๊ฒ ์ฐธ์กฐํ๋ฉด๋จ
์ด๋ป๊ฒ
๋ ์ง๋ฌธ์ด 50%์ง๋ฆฌ๋ผ ๋๋ 50%์ง๋ฆฌ ๋ต๋ฐ์ ๋ชป์ค
๋ญ๋ ๋งํ๋ฉด ๋ตํด์ค์ ์๋๋ฐ
์ด๋๊ฐ ๋ฌธ์ ์ธ์ง ๋ชจ๋ฅด๋ฉด ์ฝ๋๋ฅผ ์ ๋ฆฌํด์ ๋ค ์ฌ๋ ค
์ฝ๋๊ฐ ๋๋ฌด ์ชฝํ๋ ค
์๋ ์จ๋ฐ 1+n=x์ผ๋ x๊ฐ ๊ตฌํด๋ด ์๋ฐ์
์ํ
์์ ํ์ด
์ค๋ฅ์ฝ๋ ๊ทธ๋๋ก ์ฐ์ด์ ์ฌ๋ ค๋ด
Shoot GunNumber; GunNumber = GetComponent(); ์ด๊ฑด๋ฐ ์ฝ๋ ์๋์๋ Shoot์ฌ๊ธฐ์ ๋นจ๊ฐ๋ฐ์ค
์ด๋๊ฐ ์ค๋ฅ๋จ? - dc App
์์ ๋ต๊ธ
weaponchang๋ฌ๋ ค์๋๊ณณ์ shoot๋ ๋ฌ๋ ค์๋?
์
์ค๋ฅ์ฝ๋ ์ฐ์ด์ ์ฌ๋ ค๋ด ์์ธ๋ด์ฉ ๋ณด์ด๊ฒํด์
์์ ํ์ด
๋น์ฃผ์ผ์คํ๋์ค์์ Shootํญ์ ๋ง์ฐ์ค ์ฌ๋ ค๋ณด๊ณ WeaponChange์๋ ์ฌ๋ ค๋ณด๊ณ ํ์ชฝ์ ๊ฒฝ๋ก์ด์์๋์ง ๋ด๋ด79
์์ด!
์ง๊ธ ๋ณด์ด๋๊ฑฐ๋ก ๋ฌธ์ ๊ฐ ์๋๋ฐ? shoot์ ์๋ using๋ค weaponchange์ ์ถ๊ฐํด๋ด
์ถ๊ฐํ๋๋ฐ ๋๊ฐ์
๋น์ฃผ์ผ์คํ๋์ค ๊ป๋ค๊ฐ ์ ๋ํฐ์์ ์คํฌ๋ฆฝํธ ๋๋ธํด๋ฆญํด์ ์ด์ด๋ด
๋๊ฐ์
์ฝ๋์์ผ๋ก ๋ฌธ์ ์๋๋ฐ?
์ค๋ฅธ์ชฝ ์๋ฃจ์ ํ์๊ธฐ์์ ๋ค๋ฅธ ์ด์ ๋ธ๋ฆฌ์ ์๋๊ฑฐ ์๋๋
์ ์ ๋ณ๊ฑธ๋ฆด๊ฑฐ๊ฐ์
์ค๋ฅธ์ชฝ ์๋ฃจ์ ํ์๊ธฐ์์ ๋ณด๋ฉด Shoot.cs๋ Weapon.cs๋ ๋๋ค ๊ฒฝ๋ก๊ฐ ๋๊ฐ์ด Assembly-CSharp/Assets ๋ง์?
๋๋ค ๊ฑฐ๊ธฐ์์์ด
์ฌ์ง ์ถ๊ฐํด์ค๊น?
ใ ใ
์ฌ์ง์ถ๊ฐํ์ด
๊ทผ๋ฐ ์ด๊ฒ๋ ์ ๋ํฐ ์คํํด์ ํ๋ฉด ์ฝ๋๋ ๋ฌธ์ ์์ด ์๋ ์๋๋๋ฐ ๊ทธ๋ฅ ๋ฌด์ํ ๊น?
์คํ์ด๋๋ค๊ณ ?
์ฝ๋ ์งํ๋ ๋ฌธ์ ์์ด๋๊ณ ๊ทธ๋
shoot ๋ง๊ณ ๋ค๋ฅธ ์คํฌ๋ฆฝํธ๋ ์ฐธ์กฐ ์ ๋๋
์ ๋
๊ทธ๋ผ Shoot ์ง์ด ๋ค์ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ํ๊ณ ์ ์ฐธ์กฐํด๋ด
์ด๊ฑฐ ๋ญ์ง Shoot์์๋ง Animator ์ด๋ฐ๊ฒ๋ค ์์ด ์๋์ค๋๋ฐ Shoot์ ๋ญ ๋ฌธ์ ์๋๊ฑฐ ์๋์ผ?
์ฌ์ง๋ ์ถ๊ฐํ์ด
๋ณต์ฌํ๋ค์ ์คํฌ๋ฆฝํธ ์ง์ฐ๊ณ Shoot ๋ง๊ณ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ๋ด
๊ทธ๋๋ ๊ทธ๋ฌ๋
๊ทธ๊ฑธ ์ง๊ธ ํด๋ณผ๊ฒ
์ ๋ํฐ๋ ๋น์ฃผ์ผ ์คํ๋์ค ๋ฒ๊ทธ์ธ๋ฏ ์๋๋ฉด ์ ๋ํฐ๋ ๋น์ฃผ์ผ ์คํ๋์ค ๋๊ณ ๋ค์ ์ผ๋ณด์
์ด๊ฒ๋ง์๋ค ์ ๋ํฐ๋ฅผ ์์ ๊ป๋คํค๋๊น๋๋ค ์ง์ง ์ฌ๋ํ๋ค ๋๊ฐ ์น๋ฆฌ์๋ค