using UnityEngine;

using System.Collections;


public class ShowNormals : MonoBehaviour {

public float Lenght = 0.05f;

void OnDrawGizmos(){

SkinnedMeshRenderer[] smrs = GetComponentsInChildren<SkinnedMeshRenderer>();

foreach(SkinnedMeshRenderer s in smrs){

Mesh mesh = s.sharedMesh;

Vector3[] verticles = mesh.vertices;

Vector3[] normals = mesh.normals;

Gizmos.color = Color.red;

for(int i = 0; i < verticles.Length; i++){

Gizmos.DrawLine(transform.position + verticles[i], transform.position + verticles[i] + Lenght * normals[i]);

}

}

}

}



using UnityEngine;

using System.Collections;


public class test1 : MonoBehaviour {

public int MaxScore;

void Awake(){

//PlayerPrefs.SetInt("HISCORE", 100);

//int highScore = PlayerPrefs.GetInt("HISCORE", 0);

DontDestroyOnLoad(gameObject);

}

// Use this for initialization

void Start () {

MaxScore = 1000;

}

// Update is called once per frame

void Update () {

}

void OnGUI(){

if(GUI.Button(new Rect(10, 10, 300, 100), "score")){

MaxScore += 100;

}

if(GUI.Button(new Rect(10, 150, 190, 100), "next Level")){

if(Application.loadedLevel < Application.levelCount - 1)

Application.LoadLevel(Application.loadedLevel + 1);

//Application.LoadLevelAdditive(Application.loadedLevel + 1);

}

if(GUI.Button(new Rect(200, 150, 190, 100), "prev Level")){

if(1 < Application.loadedLevel){

Application.LoadLevel(Application.loadedLevel - 1);

}

}

if(GUI.Button(new Rect(10, 250, 190, 100), "Retry")){

Application.LoadLevel(Application.loadedLevel);

}

/*

if(GUI.Button(new Rect(200, 250, 190, 100), "Additive")){

Application.LoadLevelAdditive("Test4");

}

*/

if(GUI.Button(new Rect(200, 250, 190, 100), "Additive")){

GameObject npc = GameObject.Find("NPC");

if( npc != null)

Destroy (npc);

Application.LoadLevelAdditive("Common");

}

}

}




using System.Collections;

[System.Serializable]

public class ITem{

public int price;

public Vector3 spawnPos;

}

public class Testcube : MonoBehaviour {

[Range(0, 100)]

public int HP = 50;

[HideInInspector]

public int MP = 100;

[SerializeField]

private int AP = 50;

public ITem item;

public Vector3 spawnPos;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

void OnDrawGizmos(){

Gizmos.color = new Color(255, 0, 0, 127);

for(int x = 0; x < 4; x++){

Gizmos.DrawLine(new Vector3(x, 0, 0), new Vector3(x, 0, 0));

Gizmos.DrawLine(new Vector3(0, x, 0), new Vector3(0, x, 0));

}

Gizmos.DrawIcon(transform.position, "Crab");

Gizmos.DrawSphere(transform.position, 2);

Gizmos.color = Color.blue;

Gizmos.DrawWireSphere(transform.position, 4);

}

}





'Computer Language > 유니티' 카테고리의 다른 글

SkinnedMeshRenderer  (0) 2014.06.27
GUI 씬 전환  (0) 2014.06.23
[ContextMenu("Arrange")] 활용법  (0) 2014.06.23
진행중 gamecontroller  (0) 2014.06.10
바둑 주석  (0) 2014.05.29

using UnityEngine;

using System.Collections;


public class TestGrid : MonoBehaviour {

public int Cellwidth = 2;

[ContextMenu("Arrange")]

public void Arrage(){

for(int i = 1; i < transform.childCount; i++){

GameObject child = transform.GetChild(i).gameObject;

child.transform.position += new Vector3(Cellwidth * i, 0, 0);

}

}

}


선생님꺼.

using UnityEngine;

using System.Collections;


public class TestGrid : MonoBehaviour {

public float CellWidth = 2;

public float CellHeight = 2;

public int CellCount = 5;


[ContextMenu ("Arrange")]

public void Arrange () {

Vector3 pos = transform.position;

for (int i = 0; i < transform.childCount; i++) {

Transform child = transform.GetChild(i);

pos.x += (i % CellCount) * CellWidth;

pos.y += (i / CellCount) * CellHeight;

child.position = pos;

}

}

}


'Computer Language > 유니티' 카테고리의 다른 글

GUI 씬 전환  (0) 2014.06.23
[System.Serializable] [Range(0, 100)] [HideInInspector] [SerializeField] Script Editor  (0) 2014.06.23
진행중 gamecontroller  (0) 2014.06.10
바둑 주석  (0) 2014.05.29
값과 주소.  (0) 2014.05.26

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);

}

}

}


'Computer Language > 유니티' 카테고리의 다른 글

[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

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


'Computer Language > 유니티' 카테고리의 다른 글

[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



'Computer Language > 유니티' 카테고리의 다른 글

진행중 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);

}

}


'Computer Language > 유니티' 카테고리의 다른 글

바둑 주석  (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;

}

}

}


'Computer Language > 유니티' 카테고리의 다른 글

값과 주소.  (0) 2014.05.26
LookAt()  (0) 2014.05.23
불 껏다 키기  (0) 2014.05.23
껏다 켯다 하기  (0) 2014.05.23
생명 주기와 색깔 바꾸기  (0) 2014.05.23

+ Recent posts