| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Lua란
- 비주얼 스튜디오
- c언어 콘서트 배열 2번
- c언어 최대최소
- c#온라인
- 루아
- lua download
- 루아다운로드
- for문
- c sharp hello world
- 비주얼 스튜디오 다운로드
- c샾 hello world
- c++ 등차수열 합
- N Queen Coordinates
- 2중 반복문
- c샾 헬로우 월드
- 유니티
- 온라인 비주얼 스튜디오
- c언어 콘서트 배열
- 게임제작
- N Queens Problem
- c언어 버블정렬
- lua 다운로드
- LUA
- N Queen 문제
- Lua 설명
- c언어 배열 programming
- 메이플스토리
- Lua language
- C언어 달력
Archives
- Today
- Total
Ln Go
Weapon 본문
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
public enum Type { Melee, Range };
public Type type;
public int damage;
public float rate;
public int maxAmmo;
public int curAmmo;
public BoxCollider meleeArea;
public TrailRenderer trailEffect;
public Transform bulletPos;
public GameObject bullet;
public Transform bulletCasePos;
public GameObject bulletCase;
public void Use()
{
if (type == Type.Melee)
{
StopCoroutine("Swing");
StartCoroutine("Swing");
}
else if (type == Type.Range && curAmmo > 0)
{
curAmmo--;
StartCoroutine("Shot");
}
}
IEnumerator Swing()
{
yield return new WaitForSeconds(0.2f);
meleeArea.enabled = true;
trailEffect.enabled = true;
yield return new WaitForSeconds(0.3f);
meleeArea.enabled = false;
yield return new WaitForSeconds(0.3f);
trailEffect.enabled = false;
}
IEnumerator Shot()
{
// 1. 총알 발사
// Instantiate() 함수로 총알 인스턴스화 하기
GameObject intantBullet = Instantiate(bullet, bulletPos.position, bulletPos.rotation);
Rigidbody bulletRigid = intantBullet.GetComponent<Rigidbody>();
bulletRigid.velocity = bulletPos.forward * 50;
yield return null;
GameObject intantCase = Instantiate(bulletCase, bulletCasePos.position, bulletCasePos.rotation);
Rigidbody caseRigid = intantCase.GetComponent<Rigidbody>();
Vector3 caseVec = bulletCasePos.forward * Random.Range(-3, -2) + Vector3.up * Random.Range(2, 3);
caseRigid.AddForce(caseVec, ForceMode.Impulse);
caseRigid.AddTorque(Vector3.up * 10, ForceMode.Impulse);
}
//IEnumerator : 열거형 함수 클래스
//Use() 메인루틴 -> Swing() 서브루틴 -> Use() 메인루틴
//Use() 메인루틴 + Swing() 코루틴 (Co-Op);
}
'Unity > Quad Action' 카테고리의 다른 글
| Bullet (0) | 2021.06.04 |
|---|---|
| Grenade (0) | 2021.06.04 |
| BossMissile (0) | 2021.06.04 |
| BossRock (0) | 2021.06.04 |
| Boss (0) | 2021.06.04 |
Comments