[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 47회차 미션 시작합니다.
04. 배틀로얄 - 39, 40 번을 진행합니다.
저번에 이어 사격 동작 만들기 2가 이어집니다.
코드를 따라 치는 형태를 진행하지만 Unity 실행화면도 모르고 결과를 모르니 타이핑만 치게 되는게 맞다고 하시네요..
동작하는 것을 보면 코드가 이해될 것이라고 합니다...
하지만 그랬다면 완성된 코드로 구동을 보여주며 주요 코드를 설명해주시고, 주요 코드가 빠진 프로젝트에서 주요 코드를 타이핑 해보는 방법으로 진행하셨다면 어땠을까.. 또는 기본옵션으로 동작하는 간단한 구동 코드를 먼저 하고 다양한 옵션을 하나씩 추가해본다거나 했으면 어땠을까.. 하는 마음이 드네요 ^^
public class ShootBehaviour : MonoBehaviour
{
// 이전 코드..
private void ShootWeapon(int weapon, bool firstShot = true) {
if (!isAiming || isAimBlocked || behaviourController.GetAnimator.GetBool(reloadBool) || !weapons[weapon].Shoot(firstShot)) return;
else {
burstShotCount++;
behaviourController.GetAnimator.SetTrigger(shootingTrigger);
aimBehaviour.crossHair = shootCrossHair;
behaviourController.GetCamScript.BounceVertical(weapons[weapon].recoilAngle);
Vector3 imprecision = Random.Range(-shootErrorRate, shootErrorRate) * behaviourController.playerCamera.forward; // 약간 흔들기
Ray ray = new Ray(behaviourController.playerCamera.position, behaviourController.playerCamera.forward + imprecision);
RaycastHit hit = default(RaycastHit);
if (Physics.Raycast(ray, out hit, 500f, shotMask)) {
if (hit.collider.transform != transform) { // 내가 아니고
bool isOrganic = (organicMask == (organicMask | (1 << hit.transform.root.gameObject.layer)));
DrawShoot(weapons[weapon].gameObject, hit.point, hit.normal, hit.collider.transform, !isOrganic, !isOrganic);
if (hit.collider) {
hit.collider.SendMessageUpwards("HitCallback", new HealthBase.DamageInfo(hit.point, ray.direction, weapons[weapon].bulletDamage, hit.collider), SendMessageOptions.DontRequireReceiver);
}
}
}
else {
Vector3 destination = (ray.direction * 500f) - ray.origin;
DrawShoot(weapons[weapon].gameObject, destination, Vector3.up, null, false, false);
}
SoundManager.Instance.PlayOneShotEffect((int)weapons[weapon].shotSound, gunMuzzle.position, 5f);
GameObject gameController = GameObject.FindGameObjectWithTag(TagAndLayer.TagName.GameController);
gameController.SendMessage("RootAlertNearBy", ray.origin, SendMessageOptions.DontRequireReceiver);
shotInterval = originalShotInterval;
isShotAlive = true;
}
}
public void EndReloadWeapon() {
behaviourController.GetAnimator.SetBool(reloadBool, false);
weapons[activeWeapon].EndReload();
}
private void SetWeaponCrossHair(bool armed) {
if (armed) aimBehaviour.crossHair = aimCrossHair;
else aimBehaviour.crossHair = originalCrossHair;
}
private void ShotProgress() {
if (shotInterval > 0.2f) {
shotInterval -= shootRateFactor * Time.deltaTime;
if (shotInterval <= 0.4f) {
SetWeaponCrossHair(activeWeapon > 0);
muzzleFlash.SetActive(false);
if (activeWeapon > 0) {
}
}
}
else {
isShotAlive = false;
behaviourController.GetCamScript.BounceVertical(0);
burstShotCount = 0;
}
}
private void ChangeWeapon(int oldWeapon, int newWeapon) {
if (oldWeapon > 0) {
weapons[oldWeapon].gameObject.SetActive(false);
gunMuzzle = null;
weapons[oldWeapon].Toggle(false);
}
while (weapons[newWeapon] == null && newWeapon > 0) {
newWeapon = (newWeapon + 1) % weapons.Count;
}
if (newWeapon > 0) {
weapons[newWeapon].gameObject.SetActive(true);
gunMuzzle = weapons[newWeapon].transform.Find("muzzle");
weapons[newWeapon].Toggle(true);
}
activeWeapon = newWeapon;
if (oldWeapon != newWeapon) {
behaviourController.GetAnimator.SetTrigger(changeWeaponTrigger);
behaviourController.GetAnimator.SetInteger(weaponType, weapons[newWeapon] ? (int)weapons[newWeapon].weaponType : 0);
}
SetWeaponCrossHair(newWeapon > 0);
}
/// <summary>
/// 인벤토리 역할을 하게 될 함수
/// </summary>
public void AddWeapon(InteractiveWeapon newWeapon) {
newWeapon.gameObject.transform.SetParent(rightHand);
newWeapon.transform.localPosition = newWeapon.rightHandPosition;
newWeapon.transform.localRotation = Quaternion.Euler(newWeapon.relativeRotation);
}
private bool CheckforBlockedAim() {
isAimBlocked = Physics.SphereCast(transform.position + castRelativeOrigin, 0.1f, behaviourController.GetCamScript.transform.forward, out RaycastHit hit, distToHand - 0.1f);
isAimBlocked = isAimBlocked && hit.collider.transform != transform;
behaviourController.GetAnimator.SetBool(blockedAimBool, isAimBlocked);
Debug.DrawRay(transform.position + castRelativeOrigin, behaviourController.GetCamScript.transform.forward * distToHand, isAimBlocked ? Color.red : Color.cyan);
return isAimBlocked;
}
public void OnAnimatorIK(int layerIndex) {
if (isAiming && activeWeapon > 0) {
if (CheckforBlockedAim()) return;
Quaternion targetRot = Quaternion.Euler(0, transform.eulerAngles.y, 0);
targetRot *= Quaternion.Euler(initialRootRotation);
targetRot *= Quaternion.Euler(initialHipsRotation);
targetRot *= Quaternion.Euler(initialSpineRotation);
behaviourController.GetAnimator.SetBoneLocalRotation(HumanBodyBones.Spine, Quaternion.Inverse(hips.rotation) * targetRot);
float xcamRot = Quaternion.LookRotation(behaviourController.playerCamera.forward).eulerAngles.x;
targetRot = Quaternion.AngleAxis(xcamRot + armsRotation, transform.right);
if (weapons[activeWeapon] && weapons[activeWeapon].weaponType == InteractiveWeapon.WeaponType.LONG) {
targetRot *= Quaternion.AngleAxis(9f, transform.right);
targetRot *= Quaternion.AngleAxis(20f, transform.up);
}
targetRot *= spine.rotation;
targetRot *= Quaternion.Euler(initialCheckRotation);
behaviourController.GetAnimator.SetBoneLocalRotation(HumanBodyBones.Chest, Quaternion.Inverse(spine.rotation) * targetRot);
}
}
private void LateUpdate() {
if (isAiming && weapons[activeWeapon] && weapons[activeWeapon].weaponType == InteractiveWeapon.WeaponType.SHORT) {
leftArm.localEulerAngles = leftArm.localEulerAngles + leftArmShortAim;
}
}
}
What is the purpose of this lecture?
Ooops. BattleRoyale and BattleGround is the same project... so should I continue?
<위의 코드들은 제가 보면서 주요한 함수, 코드를 확인하기 위해 타이핑한 용도로, 전체 소스코드가 아님에 주의해 주세요. 전체 코드는 교육 수강을 하면 완벽하게 받으실 수가 있답니다 ^^>
패스트캠퍼스 - 올인원 패키지 : 유니티 포트폴리오 완성 bit.ly/2R561g0
유니티 게임 포트폴리오 완성 올인원 패키지 Online. | 패스트캠퍼스
게임 콘텐츠 프로그래머로 취업하고 싶다면, 포트폴리오 완성은 필수! '디아블로'와 '배틀그라운드' 게임을 따라 만들어 보며, 프로그래머 면접에 나오는 핵심 개념까지 모두 잡아 보세요!
www.fastcampus.co.kr
'[컴퓨터] > 웹 | 앱 | 게임 개발' 카테고리의 다른 글
[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 49회차 미션 (0) | 2020.12.06 |
---|---|
[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 48회차 미션 (0) | 2020.12.05 |
[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 46회차 미션 (0) | 2020.12.03 |
[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 45회차 미션 (0) | 2020.12.02 |
[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 44회차 미션 (0) | 2020.12.01 |