Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 오류
- 파이썬
- 시작해요 언리얼 2022
- W3Schools
- 프로그래밍
- C#
- DP
- 기초
- parameter
- Algorithm
- 재귀
- String
- dfs
- Tutorial
- w3school
- Basic
- UE5
- c++
- python
- Unity
- Programming
- github
- loop
- dynamic
- guide
- 문제풀이
- Class
- 백준
- Material
- Unreal Engine 5
Archives
- Today
- Total
행복한 개구리
Unity 3D 전설의 궁수 2021.04.10 본문
**밑으로 내리시면 날짜별로 올려뒀습니다.
2021.04.10
-죽는모션 반복재생 해결
-주인공이 제 3사분면쪽으로 바라보지 않는 문제 해결
-총알이 갑자기 사라진다거나 너무 짧은 위치만 이동하는 문제 해결
-총알이 벽에 맞거나 일정 좌표 이상 나가면 사라지는 것 구현
-주인공이 벽 바깥으로 나가는 문제 해결
-주인공 뛸 때 발 뒤에 먼지나는 것 구현
└뛰면 재생, 멈춘 상태에선 일시정지, 죽으면 정지로 구현
-주인공이 죽으면 총알 안나오는 것 구현
-플레이중에 게임오버UI 꺼놓기 구현
-게임오버 UI출력 구현
===========================================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeroController : MonoBehaviour
{
public Rigidbody playerRigidbody;
public BoxCollider playerBoxC;
public CapsuleCollider playerCapsuleC;
public ParticleSystem smoke;
Animation anime;
float maxHp = 20;
float damage = 5;
float speed = 3.0f;
float hp;
float delta;
bool isDie;
// Start is called before the first frame update
void Start()
{
this.anime = GetComponent<Animation>();
this.anime.Play("idle@loop");
this.hp = maxHp;
this.isDie = false;
}
// Update is called once per frame
void Update()
{
this.transform.position = new Vector3(Mathf.Clamp(this.transform.position.x, -4f, 4f), 0, Mathf.Clamp(this.transform.position.z, -9f, 9f));
float xInput = Input.GetAxis("Horizontal");
float zInput = Input.GetAxis("Vertical");
float xSpeed = xInput * speed;
float zSpeed = zInput * speed;
Vector3 newVeloc = new Vector3(xSpeed, 0, zSpeed);
playerRigidbody.velocity = newVeloc;
float d = newVeloc.magnitude;
if (this.hp > 0 && d >= 0.02f)
{
this.anime.Play("run@loop");
this.smoke.Play();
Vector3 lookAt = newVeloc + this.transform.position;
this.transform.LookAt(lookAt);
}
else if (this.hp > 0 && d < 0.02f)
{
this.anime.Play("idle@loop");
this.smoke.Pause();
this.transform.position = this.transform.position;
}
if (this.hp <= 0)
{
this.isDie = true;
this.smoke.Stop();
}
}
public void DecreaseHp()
{
this.hp -= 20;
Debug.LogFormat("this.hp : {0}", this.hp);
}
public void Die()
{
this.anime.Play("die");
this.playerBoxC.isTrigger = false;
this.playerCapsuleC.isTrigger = false;
this.speed = 0;
this.delta += Time.deltaTime;
if(this.delta > 0.7f)
{
this.anime.Stop();
}
if (this.delta > 2.5f)
{
this.gameObject.SetActive(false);
/*GameObject smoke = Instantiate()*/
}
}
public bool IsDie()
{
return this.isDie;
}
public float GetHp()
{
return this.hp;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletController : MonoBehaviour
{
float speed = 4f;
public Rigidbody bulletRigid;
// Start is called before the first frame update
void Start()
{
Destroy(this.gameObject, 7f);
this.bulletRigid.velocity = this.transform.forward * speed;
}
// Update is called once per frame
void Update()
{
if (Mathf.Abs(this.gameObject.transform.position.x) >= 5.1f ||
Mathf.Abs(this.gameObject.transform.position.z) >= 10.1f ||
this.gameObject.transform.position.y < 0)
{
Destroy(this.gameObject);
}
}
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
HeroController hero = other.GetComponent<HeroController>();
hero.DecreaseHp();
/*Debug.LogFormat("this.hp : {0}", hero.GetHp());*/
Destroy(this.gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InGame : MonoBehaviour
{
public UI ui;
public BulletSpawner BS;
public GameObject Hero;
bool isOver;
// Start is called before the first frame update
void Start()
{
this.Hero = GameObject.Find("Hero");
this.ui.GOBack.gameObject.SetActive(false);
this.isOver = false;
}
// Update is called once per frame
void Update()
{
HeroController hero = this.Hero.GetComponent<HeroController>();
if (this.isOver == true)
{
this.ui.GOBack.gameObject.SetActive(true);
}
if (hero.IsDie() == true)
{
hero.Die();
BS.SetOff();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI : MonoBehaviour
{
public Image GOBack;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletSpawner : MonoBehaviour
{
public GameObject bulletPrefab;
float min;
float max;
float time;
float rate;
bool isOn;
Vector3 spawnPos;
Quaternion rotation;
Transform target;
// Start is called before the first frame update
void Start()
{
isOn = true;
this.time = 0;
this.min = 1f;
this.max = 2.5f;
this.rate = Random.Range(this.min, this.max);
this.target = FindObjectOfType<HeroController>().transform;
this.spawnPos = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
}
// Update is called once per frame
void Update()
{
this.time += Time.deltaTime;
if (isOn == true)
{
if (this.time > this.rate)
{
this.time = 0;
GameObject bullet = Instantiate(this.bulletPrefab, this.spawnPos, this.transform.rotation);
this.transform.LookAt(this.target);
this.rate = Random.Range(this.min, this.max);
}
}
}
public void SetOff()
{
isOn = false;
}
}
'Unity > Project : Unity 3D 전설의 궁수' 카테고리의 다른 글
Unity 3D 전설의 궁수 21.04.07 (0) | 2021.04.19 |
---|