Unity3D
Unity3D 관련
by 히아레인
Tag
Media Log
Location Log
Guest Book
Admin
Write
Article Category
분류 전체보기
(495)
유니티
(227)
Note
(104)
스크립트
(123)
유니티로 게임을 만드는 10가..
(0)
챕터 1 도깨비
(0)
절대강좌
(0)
보고싶은책
(32)
cocos2d-x
(6)
웹관련
(13)
자바스크립트
(3)
DB
(5)
PHP & MySql 정리
(0)
잡다한것들전부
(207)
클레이 사격
(0)
팁
(61)
세팅
(1)
프로젝트
(0)
런게임
(0)
따라하기
(0)
Tutorial
(7)
기타
(15)
c++ STL
(12)
C, C++, C#
(15)
안드로이드
(15)
언어
(0)
수학
(0)
cookbook관련
(2)
물리구현
(0)
심화
(1)
프로젝트
(0)
팁
(38)
포스팅예정
(0)
Basic Concepts
(7)
세팅
(4)
소식
(1)
2D 관련 자료
(2)
에셋
(2)
C#
(6)
Card
(0)
계란받기게임
(0)
Flying Owl
(0)
Dungeon의 Alien
(0)
Temple Run
(0)
Memory Test
(0)
운석피하기
(0)
공식예제
(13)
예제따라하기
(0)
퍼즐
(0)
참고사이트
(4)
유니티 코리아
(1)
Notice
Recent Article
UGUI Text 글자 간격..
다른 확률을 가진 아이..
유니티 서버 관련.
유니티 5.x 애니메이션..
git 언어별 ignore 리..
Recent Comment
정리가 너무 잘 되어..
[승인대기]
[승인대기]
대단하군요
감사합니다. ^
메트리얼 쉐이더를 tra..
안녕하세요. 이런 움직..
Sprites/default 메트..
머터리얼을 Sprites/de..
프로그램 실행하자마자..
Recent Trackback
水泳 rx
Combat System 4
|
카테고리 없음
2014. 4. 18. 15:59
Posted by 히아레인
몬스터 공격 가능
캐릭터 죽음
ClickToMove는 die 변수 한개 추가됨.
using UnityEngine; using System.Collections; //주인공 공격 public class Fighter : MonoBehaviour { public GameObject opponent; //공격 애니메이션. public AnimationClip attack; public AnimationClip dieClip; //데미지 public int health; public int damage; //공격시간, 공격여부 public double impactTime; public bool impacted; //공격사거리 public float range; bool started; bool ended; // Use this for initialization void Start () { } // Update is called once per frame void Update () { Debug.Log(health + "Player"); if(Input.GetKey(KeyCode.Space) && inRange()) { animation.Play(attack.name); ClickToMove.attack = true; //공격시 적 바라보게하기 - null 체크. if(opponent != null) { transform.LookAt(opponent.transform); } } //modify comat system 3 if(animation[attack.name].time > 0.9 * animation[attack.name].length) { ClickToMove.attack = false; impacted = false; } impact(); die (); } //데미지를 주는 순간 void impact() { if(opponent != null && animation.IsPlaying(attack.name) && ! impacted) { //modify comat system 3 if(animation[attack.name].time > (animation[attack.name].length * impactTime) && (animation[attack.name].time < 0.9 * animation[attack.name].length) ) { opponent.GetComponent<Mob>().getHit(damage); impacted = true; } } } //몬스터에게 맞을시 public void getHit(int damage) { health = health - damage; if(health < 0) { health = 0; } } bool inRange() { return (Vector3.Distance(opponent.transform.position, transform.position) <= range ); } //If dead returns true or else return false public bool isDead() { if(health <= 0) { return true; } else { return false; } } void die() { if( isDead() && !ended) { if(! started) { ClickToMove.die = true; animation.Play(dieClip.name); started = true; } if(started && !animation.IsPlaying(dieClip.name)) { //What ever you want to do Debug.Log("You have died"); health = 100; ended = true; started = false; ClickToMove.die = false; } } } }
using UnityEngine; using System.Collections; public class Mob : MonoBehaviour { public float speed; public float range; public CharacterController controller; public Transform player; private Fighter opponent; public AnimationClip attackClip; public AnimationClip run; public AnimationClip idle; public AnimationClip die; public double impactTime = 0.36; //hp public int health; public int damage; private bool impacted; // Use this for initialization void Start () { opponent = player.GetComponent<Fighter>(); } // Update is called once per frame void Update () { if(! isDead()) { if(! inRange()) { chase(); } else { animation.Play(attackClip.name); attack(); if(animation[attackClip.name].time > 0.9 * animation[attackClip.name].length) { impacted = false; } } } else { dieMethod(); //animation.CrossFade(die.name); } } void attack() { if(animation[attackClip.name].time > animation[attackClip.name].length * impactTime && ! impacted && animation[attackClip.name].time < 0.9 * animation[attackClip.name].length) { opponent.getHit(damage); impacted = true; } } //플레이어와 거리 계산. bool inRange() { if(Vector3.Distance(transform.position, player.position) < range) { return true; } else { return false; } } //플레이어가 공격시 Fighter 스크립트에서 호출 public void getHit(int damage) { health = health - damage; if(health < 0) { health = 0; } } void chase() { //플레이어 바라보기. //플레이어 다가가기 transform.LookAt(player.position); controller.SimpleMove(transform.forward * speed); animation.CrossFade(run.name); } void dieMethod() { animation.Play(die.name); if(animation[die.name].time > animation[die.name].length * 0.9) { Destroy(gameObject); } } bool isDead() { if(health <= 0) { return true; } else { return false; } } void OnMouseOver() { player.GetComponent<Fighter>().opponent = gameObject; } }
Combat System 4.z01
Combat System 4.zip
공유하기
글 요소
구독하기
Unity3D
저작자표시
Trackback
0
And
Comment
0
Trackback
|
1
|
···
|
131
|
132
|
133
|
134
|
135
|
136
|
137
|
138
|
139
|
···
|
495
|
Tag Cloud
action
안드로이드
COCOS2D-X
파티클
Flip
블로그
서적
php
C#
c++
계란받기
cocos2d
하이라이트
게임
유니티
이클립스
JNI
튜토리얼
Roguelike
Unity3d
코드
러너게임
디자인패턴
구글
It
Unity2D
NGUI
transform
소스
itween
상수
인벤토리
Calendar
«
2020/06
»
일
월
화
수
목
금
토
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
Archive
2015/07
(3)
2015/06
(4)
2015/05
(1)
2015/04
(3)
2015/03
(2)
My Link
유니티 강좌
유니티 코리아
ElMaHe
유니티 정보를 나누어..
데브코리아 - ★게임개..
순순디자인
The Anarchists
2D Toolkit - Document..
cocos2d-x 공식 사이트
안드로이드 개발자
JSON 오류 검사
Stack Overflow
금지된 엑시노아의 비..