데이터베이스 설계와 구축 이춘식.
TCP/IP Illustrated: The Implementation by Gary R. Wright, W. Richard Stevens
'Computer Language > 하루하루' 카테고리의 다른 글
게임 만들기 (0) | 2014.06.10 |
---|---|
사. (0) | 2014.06.07 |
서버 만들시. (0) | 2014.04.16 |
데이터베이스 설계와 구축 이춘식.
TCP/IP Illustrated: The Implementation by Gary R. Wright, W. Richard Stevens
게임 만들기 (0) | 2014.06.10 |
---|---|
사. (0) | 2014.06.07 |
서버 만들시. (0) | 2014.04.16 |
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class CharaterControl : MonoBehaviour {
public AnimationClip idleAnimation;
public AnimationClip walkAnimation;
public AnimationClip runAnimation;
public AnimationClip jumpPoseAnimation;
public AnimationClip fallPoseAnimation;
public Animation animationTarget;
public float idleAnimationSpeed = 0.5f;
public float walkAnimationSpeed = 1.5f;
public float runAnimationSpeed = 1.5f;
public float jumpAnimationSpeed = 4.0f;
public float fallAnimationSpeed = 0.1f;
public float speed = 2.0f;
public float runSpeed = 5.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private CharacterController controller;
//transfortation
private float t_verticalSpeed = 0.0f;
private float t_moveSpeed = 0.0f;
private Vector3 v3_moveDirection = Vector3.zero;
//boolean
private bool b_isRun;
private bool b_isBackward;
private bool b_isJumping;
//rotation
private Quaternion q_currentRotation;
private Quaternion q_rot;
private float t_rotationSpeed = 1.0f;
//vector3
private Vector3 v3_forward;
private Vector3 v3_right;
private CollisionFlags c_collisionFlags;
//air time
private float a_inAirTime = 0.0f;
private float a_inAirStartTime = 0.0f;
private float a_minAirTime = 0.15f;
void Awake(){
controller = GetComponent<CharacterController>();
b_isRun = false;
b_isBackward = false;
b_isJumping = false;
t_moveSpeed = speed;
c_collisionFlags = CollisionFlags.CollidedBelow;
animationTarget.wrapMode = WrapMode.Loop;
animationTarget[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
animationTarget[fallPoseAnimation.name].wrapMode = WrapMode.ClampForever;
animationTarget[idleAnimation.name].wrapMode = WrapMode.Loop;
animationTarget[runAnimation.name].wrapMode = WrapMode.Loop;
animationTarget[walkAnimation.name].wrapMode = WrapMode.Loop;
}
// Use this for initialization
void Start () {
a_inAirStartTime = Time.time;
}
public bool IsGrounded(){
return (c_collisionFlags & CollisionFlags.CollidedBelow) != 0;
}
public bool IsJumping(){
return b_isJumping;
}
public bool IsAir(){
return (a_inAirTime > a_minAirTime);
}
public bool IsMoveBackward(){
return b_isBackward;
}
// Update is called once per frame
void Update () {
Transform cameraTransform = Camera.main.transform;
v3_forward = cameraTransform.TransformDirection(Vector3.forward);
v3_forward.y = 0;
v3_right = new Vector3(v3_forward.z, 0, -v3_forward.x);
float t_hor = Input.GetAxis("Horizontal");
float t_ver = Input.GetAxis("Vertical");
if(t_ver < 0){
b_isBackward = true;
}else{
b_isBackward = false;
}
Vector3 v3_targetDirection = (t_hor * v3_right) + (t_ver * v3_forward);
if(v3_targetDirection != Vector3.zero){
v3_moveDirection = Vector3.Slerp(v3_moveDirection, v3_targetDirection ,t_rotationSpeed * Time.deltaTime);
v3_moveDirection = v3_moveDirection.normalized;
}
else{
v3_moveDirection = Vector3.zero;
}
if(!b_isJumping){
if(Input.GetKey(KeyCode.LeftShift)){
b_isRun = true;
t_moveSpeed = runSpeed;
}else{
b_isRun = false;
t_moveSpeed = speed;
}
if(Input.GetButton("Jump")){
t_verticalSpeed = jumpSpeed;
b_isJumping = true;
}
}
if(IsGrounded()){
t_verticalSpeed = 0.0f;
b_isJumping = false;
a_inAirTime = 0.0f;
a_inAirStartTime = Time.time;
}else{
t_verticalSpeed -= gravity * Time.deltaTime;
a_inAirTime = Time.time - a_inAirStartTime;
}
Vector3 v3_movement = (v3_moveDirection * t_moveSpeed) + new Vector3(0, t_verticalSpeed, 0);
v3_movement *= Time.deltaTime;
c_collisionFlags = controller.Move(v3_movement);
//animation play
if(b_isJumping){
if(controller.velocity.y > 0){
animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
animation.CrossFade(jumpPoseAnimation.name, 0.1f);
}else{
animation[fallPoseAnimation.name].speed = fallAnimationSpeed;
animation.CrossFade(fallPoseAnimation.name, 0.1f);
}
}else{
if(IsAir()){
animation[fallPoseAnimation.name].speed = fallAnimationSpeed;
animation.CrossFade(fallPoseAnimation.name, 0.1f);
}else{
if(controller.velocity.sqrMagnitude < 0.1f){
animation[idleAnimation.name].speed = idleAnimationSpeed;
animation.CrossFade(idleAnimation.name, 0.1f);
}else{
if(b_isRun){
animation[runAnimation.name].speed = runAnimationSpeed;
animation.CrossFade(runAnimation.name, 0.1f);
}else{
animation[walkAnimation.name].speed = walkAnimationSpeed;
animation.CrossFade(walkAnimation.name, 0.1f);
}
}
}
}
//character rotation update/
if(v3_moveDirection != Vector3.zero){
transform.rotation = Quaternion.LookRotation(v3_moveDirection);
}
}
}
[System.Serializable] [Range(0, 100)] [HideInInspector] [SerializeField] Script Editor (0) | 2014.06.23 |
---|---|
[ContextMenu("Arrange")] 활용법 (0) | 2014.06.23 |
바둑 주석 (0) | 2014.05.29 |
값과 주소. (0) | 2014.05.26 |
LookAt() (0) | 2014.05.23 |
목표 : Coin*10가능
제한조건:
1. npc(경비병)*10, 코인 지킨다 raycast 플레이어 공격
2. npc*10 좀비 Player가 근처에 있으면 쫒아 간다.
3. player : npc(하트 3개)를 (bullet)rigid body공격 가능 맞으면 물리친다. 뒤로 물러난다.
db 책 (0) | 2014.06.11 |
---|---|
사. (0) | 2014.06.07 |
서버 만들시. (0) | 2014.04.16 |
db 책 (0) | 2014.06.11 |
---|---|
게임 만들기 (0) | 2014.06.10 |
서버 만들시. (0) | 2014.04.16 |
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public const int Line = 9;
public const int MaxStone = 30;
public int Grid = 1; //None
const int EMPTY = 0;
const int BLACK = 1;
const int WHITE = 2;
const int WALL = 3;
int[] current = {0, 0} ;
int[] captured = {0, 0} ;
public Transform[] StoneBox;//parent
bool[,] lifePoint = new bool[Line + 2, Line + 2];//11*11
int color = BLACK;//1
public GameObject[,] Stones = new GameObject[2, MaxStone];
string[] StoneName = {"Black", "White"} ;
int[,] checkPoint = new int[4, 2] { {0, 1} , {1, 0} , {0, -1} , {-1, 0} };
public int [,] Jum = new int[Line + 2, Line + 2];
public GameObject [, ] JumObject = new GameObject[Line + 2, Line + 2];//11*11
void Start () {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < MaxStone; j++) {
Stones[i, j] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Stones[i, j].renderer.material.color = (i == 0) ? Color.black : Color.white;
Stones[i, j].name = string.Format("{0}[{1}]", StoneName[i], j);
Stones[i, j].transform.position = new Vector3(-7 + 14 * i, 0, -3.0f + (float)j * 0.3f);
Stones[i, j].transform.parent = StoneBox[i];
Stones[i, j].transform.localScale = new Vector3(1.0f, 0.4f, 1.0f);
Stones[i, j].AddComponent(typeof(Stone));
}//for
}//for
for (int x = 0; x <= Line; x++) {// 0 ~ 9
Jum[x, 0] = WALL;
Jum[x, Line + 1] = WALL;
}//for
for (int z = 0; z <= Line; z++) {// 0 ~ 9
Jum[0, z] = WALL;
Jum[Line + 1, z] = WALL;
}//for
}//Start
void Update () {
if (Input.GetMouseButtonDown(0)) {//left click
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//camera to touchpoint
RaycastHit hit;
if (Physics.Raycast(ray, out hit) && current[color - 1] < MaxStone) {
Vector3 pos = hit.point;
//print ("Hit.Point : "+pos);
pos.x = Mathf.Clamp(Mathf.Round (pos.x), -Line / 2, Line / 2);
pos.y = 0.2f;
pos.z = Mathf.Clamp(Mathf.Round (pos.z), -Line / 2, Line / 2);
int px, pz;
px = 1 + (int)(pos.x + Line * 0.5f);
pz = 1 + (int)(pos.z + Line * 0.5f);
if (Jum[px, pz] != EMPTY) {
JumObject[px, pz].SendMessage("PlayScale");
return;
}//Empty if
GameObject stone = Stones[color - 1, current[color - 1]];
stone.transform.position = pos;
//print (string.Format("Move : color = {0}, px = {1}, pz = {2}", (color == BLACK) ? "B" : "W", px, pz));
Jum[px, pz] = color;
JumObject[px, pz] = stone;
checkLife2(px, pz);
current[color - 1]++;
color = (color == BLACK) ? WHITE : BLACK;
}//Physics if
}//Click if
}//Update
bool getLifePoint(int x, int z) {
int i = 0;
for (i = 0; i < 4; i++) {
int x1 = x + checkPoint[i, 0];// 0, 1, 0, -1
int z1 = z + checkPoint[i, 1];// 1, 0, -1, 0
if (Jum[x1, z1] == EMPTY)
return true;
}//for
return false;
}//getLifePoint
void deleteJum (int x, int z) {
if (Jum[x, z] == BLACK) {
Jum[x, z] = EMPTY;
captured[0]++;
JumObject[x, z].transform.position = new Vector3(2.0f + captured[0] * 0.2f, 0.5f, 6.0f);
} else if (Jum[x, z] == WHITE) {
Jum[x, z] = EMPTY;
captured[1]++;
JumObject[x, z].transform.position = new Vector3(-2.0f - captured[1] * 0.2f, 0.5f, 6.0f);
}//if
}//deleteJum
void checkLife2 (int lastX, int lastZ) {
for (int x = 1; x <= Line; x++) {// 1 ~ 9
for (int z = 1; z <= Line; z++) {// 1 ~ 9
lifePoint[x, z] = getLifePoint(x, z);
}//for
}//for
for (int x = 1; x <= Line; x++) {// 1 ~ 9
for (int z = 1; z <= Line; z++) {// 1 ~ 9
if (Jum[x, z] == EMPTY)
continue;
for (int i = 0; i < 4; i++) {
int x1 = x + checkPoint[i, 0];
int z1 = z + checkPoint[i, 1];
if (Jum[x, z] == Jum[x1, z1] && lifePoint[x1, z1] == true) {
lifePoint[x, z] = true;
break;
}//if
}//for
}//for
}//for
for (int x = 1; x <= Line; x++) {
for (int z = 1; z <= Line; z++) {
if (Jum[x, z] != EMPTY && lifePoint[x, z] == false)
deleteJum(x, z);
}//for
}//for
}//checkLife2
void checkLife () {
for (int x = 1; x <= Line; x++) {
for (int z = 1; z <= Line; z++) {
if (Jum[x, z] == EMPTY)
continue;
int i = 0;
for (i = 0; i < 4; i++) {
int x1 = x + checkPoint[i, 0];
int z1 = z + checkPoint[i, 1];
if (Jum[x1, z1] == Jum[x, z] || Jum[x1, z1] == EMPTY) {
break; // LIFE
}//if
}//for
if (i < 4)
continue;
deleteJum(x, z);
}//for
}//for
}//checkLife
}//class
[ContextMenu("Arrange")] 활용법 (0) | 2014.06.23 |
---|---|
진행중 gamecontroller (0) | 2014.06.10 |
값과 주소. (0) | 2014.05.26 |
LookAt() (0) | 2014.05.23 |
vector3 사용예제 (0) | 2014.05.23 |
진행중 gamecontroller (0) | 2014.06.10 |
---|---|
바둑 주석 (0) | 2014.05.29 |
LookAt() (0) | 2014.05.23 |
vector3 사용예제 (0) | 2014.05.23 |
불 껏다 키기 (0) | 2014.05.23 |
using UnityEngine;
using System.Collections;
public class Turret : MonoBehaviour {
public Transform target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.LookAt(target);
}
}
바둑 주석 (0) | 2014.05.29 |
---|---|
값과 주소. (0) | 2014.05.26 |
vector3 사용예제 (0) | 2014.05.23 |
불 껏다 키기 (0) | 2014.05.23 |
껏다 켯다 하기 (0) | 2014.05.23 |
using UnityEngine;
using System.Collections;
public class newsource : MonoBehaviour {
public int hp;
public float moveSpeed = 10.0f;
public float turnSpeed = 50.0f;
void Awake(){
print ("Awake name = " + name);
}
void OnEnable(){
print ("OnEnabel name = " + name);
}
void OnDisable(){
print ("OnDisable name = " + name);
}
// Use this for initialization
void Start () {
print ("Start name = " + name);
}
void Reset(){
print ("Reset name = " + name);
hp = 20;
}
void FixedUpdate(){
//print ("FixedUpdate = " + Time.deltaTime);
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.UpArrow)){
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.DownArrow)){
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Rotate(Vector3.up *-turnSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.RightArrow)){
transform.Rotate(Vector3.up * turnSpeed * Time.deltaTime);
}
if(Input.GetKeyDown(KeyCode.R)){
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G)){
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B)){
gameObject.renderer.material.color = Color.blue;
}
}
}
값과 주소. (0) | 2014.05.26 |
---|---|
LookAt() (0) | 2014.05.23 |
불 껏다 키기 (0) | 2014.05.23 |
껏다 켯다 하기 (0) | 2014.05.23 |
생명 주기와 색깔 바꾸기 (0) | 2014.05.23 |
using UnityEngine;
using System.Collections;
public class LightMan : MonoBehaviour {
Light myLight;
Transform t;
// Use this for initialization
void Start () {
myLight = GetComponent<Light>(); //남의 꺼를 가져올때 쓰입니다.
t = GetComponent<Transform>();
t = GetComponent("Transform") as Transform;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.L)){
myLight.enabled = !myLight.enabled;
}
}
}
LookAt() (0) | 2014.05.23 |
---|---|
vector3 사용예제 (0) | 2014.05.23 |
껏다 켯다 하기 (0) | 2014.05.23 |
생명 주기와 색깔 바꾸기 (0) | 2014.05.23 |
로그 찍기 (0) | 2014.05.23 |
using UnityEngine;
using System.Collections;
public class newsource : MonoBehaviour {
public int hp;
void Awake(){
print ("Awake name = " + name);
}
void OnEnable(){
print ("OnEnabel name = " + name);
}
void OnDisable(){
print ("OnDisable name = " + name);
}
// Use this for initialization
void Start () {
print ("Start name = " + name);
}
void Reset(){
print ("Reset name = " + name);
hp = 20;
}
void FixedUpdate(){
print ("FixedUpdate = " + Time.deltaTime);
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.R)){
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G)){
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B)){
gameObject.renderer.material.color = Color.blue;
}
}
}
vector3 사용예제 (0) | 2014.05.23 |
---|---|
불 껏다 키기 (0) | 2014.05.23 |
생명 주기와 색깔 바꾸기 (0) | 2014.05.23 |
로그 찍기 (0) | 2014.05.23 |
오브젝트 찾고 지우기 1. 태그 2. 이름 (0) | 2014.05.23 |