์ด๊ฑฐ Shoot์—์„œ ๋ฌธ์ œ ์ƒ๊ธด๊ฑฐ ๊ฐ™์•„์„œ ๋ชจ๋…ธ๋น„ํ—ค์ด๋น„์–ด ์ง€์šฐ๊ณ  ๋‹ค์‹œ ์ ์–ด์„œ ์ €์žฅ ๋ฐ•์•˜๋Š”๋ฐ ์ €๊ฑธ ์ฐธ์กฐ ๋ชปํ•˜๋Š”๋ฐ

CS0246 ์˜ค๋ฅ˜๋„ ํ•œ๋ฒˆ๋–ณ๋‹ค๊ฐ€ ์‚ฌ๋ผ์กŒ์–ด

viewimage.php?id=2abcdd23dad63db0&no=24b0d769e1d32ca73cec87fa11d0283141b58444220b0c04398cc92aeede06e5273bde7a2026214f3e09c3b0dd1825b6dc6a8a425883e5540837cb590ac4db7024f00e


viewimage.php?id=2abcdd23dad63db0&no=24b0d769e1d32ca73cec87fa11d0283141b58444220b0c04398cc92aeede06e5273bde7a2026214f3e09c3b0dd1825b6dc6a8a425883e5555e35cc5b5896897092e117


viewimage.php?id=2abcdd23dad63db0&no=24b0d769e1d32ca73cec87fa11d0283141b58444220b0c04398cc92aeede06e5273bde7a2026214f3e09c3b0dd1825b6dc6a8a425883e5525737cc5d0e948b70f2b5e2

์˜ˆ๋ฅผ๋“ค์–ด Shoot m_shoot;

์ด๋Ÿฐ์‹์œผ๋กœํ•ด์„œ ํ•˜๋Š”๋ฐ ๊ฐ‘์ž๊ธฐ ํ˜•์‹์„ ์ฐพ์„์ˆ˜ ์—†๋‹ค๋ฉด์„œ ์˜ค๋ฅ˜๊ฐ€ ๋œจ๋Š”๋ฐ ์™œ์ด๋Ÿฌ๋Š”์ง€ ์•„๋Š”์•  ์—†๋ƒ


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class WeaponChange : MonoBehaviour

{

Shoot GunNumber;

GameObject[] Image;

public Animator animator;

private void Awake()

{

GunNumber = GetComponent<Shoot>();

}

void Start()

{

}


// Update is called once per frame

void Update()

{

}

public void OnButton()

{

animator.SetTrigger("ChandWeaPon");

if (GunNumber.WeaPonType == 0)

{

GunNumber.WeaPonType++;

animator.SetInteger("WeaPonType", 1);

}

else if (GunNumber.WeaPonType == 1)

{

GunNumber.WeaPonType = 0;

animator.SetInteger("WeaPonType", 0);

}

else

{

GunNumber.WeaPonType = 0;

animator.SetInteger("WeaPonType", 0);

}

}

}

์ด๊ฒŒ ์ฐธ์กฐ ํ•˜๋ ค๋Š”๋Œ€๊ณ 

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";
}
}
}
}

์ด๊ฒŒ Shoot