using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
ย ย public float shootSpeed, shootTimer;ย ย ย ย ย
ย ย public Animator animator;
ย ย public Transform firePoint;
ย ย public GameObject bullet;
ย ย // Start is called before the first frame update
ย ย void Start()
ย ย {
ย ย ย ย animator = GetComponent<Animator>();
ย ย }
ย ย // Update is called once per frame
ย ย void Update()
ย ย {
ย ย ย ย if (Input.GetButtonDown("Fire1"))
ย ย ย ย {
ย ย ย ย ย ย animator.SetBool("Shooting", true);
ย ย ย ย ย ย bullet.gameObject.SetActive(true);
ย ย ย ย ย ย Shoot();
ย ย ย ย }
ย ย ย ย else if (Input.GetButtonUp("Fire1"))
ย ย ย ย {
ย ย ย ย ย ย animator.SetBool("Shooting", false);
ย ย ย ย ย ย bullet.gameObject.SetActive(false);
ย ย ย ย ย ย Destroy(GameObject.FindWithTag("Weapon"));
ย ย ย ย }
ย ย }
ย ย void Shoot()
ย ย {ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย
ย ย ย ย Instantiate(bullet, firePoint.position, firePoint.rotation);ย ย ย ย ย ย ย
ย ย }
}
์์๊พธ์๋ถ๋ ๋ค์์์ ๊น์? ใ ใ
firepoint rotation์ ์์ฑ๋๋ ์ค๋ธ์ ํธ ์๋ ๊ฐ๋๋ก ๋ฐ๊ฟ๋ณด์ธ์ฌ
์๋๋ฉด ์์ฑ๋ ์ค๋ธ์ ํธ์ ์ขํ๊ฐ์ด ์ด๋ฏธ ๋ฐ๋์ด ์๋ ์ฑ์ฌ์ ์ฒ์์ ์์ฑ๋ ๋ ๊ทธ ์ขํ ๊ทธ๋๋ก ๊ฐ์ ธ์ค๋๊ฑฐ ๊ฐ๋ค์ฌ.
์ฝ๋๋ ๋ญ๊ฐ ์ด์ํ๊ฑฐ๊ฐ์์ฌ ๋ฐ์ฌ๋ฒํผ์ ๋๋ ์๋๋ ์๊ฒ ๋๋ฐ ์ ๋ฐ์ฌ๋ฒํผ์ ๋์๋ bullet์ด ๋นํ์ฑํ๋๊ฒ ํ์ จ๋์ง ๋ชจ๋ฅด๊ฒ ์ด์ฌ. ๊ฑ ์ด์ ์์ฑํ๋ ์ฝ๋๋ฅผ shoot() ํจ์์๋ค ์ฎ๊ธฐ๊ณ ๋ฒํผ ๋๋ ์ ๋๋ง ํจ์ ์คํ๋๊ฒ ํ๋๊ฒ ํฉ๋ฆฌ์ ์ธ๊ฑฐ๊ฐ์๋ณด์ฌ์
์ค ๋ต๋ณ๊ฐ์ฌ๋๋ ค์. ์ขํ์ธ์์ ์๋ชปํ์๋ค์!!
์ฝ๋๋์์ ํด๋ณผ๊ผ์ ใ ใ ;; ๊ฐ์ฌ์ฉ
๋ค ์ ๋ ๊ฐ๋ ๊ทธ๋์ฌ ์์ฑ๋ ์ค๋ธ์ ํธ ์ขํ๋ 0,0,0์ผ๋ก ํด๋์ผ ์๋ํ ๋๋ก ๋์ํ๋๋ฐ ์ค๋ธ์ ํธ ์๋ฌด๋ ๊ฒ๋ ๋ง๋ค๊ณ ํ๋ฆฌํนํํ๋ ๊ณผ์ ์์ ์์ฃผ ๊น๋จน๋๋ผ๊ตฌ์ฌ