public void OnButtonCharacterShow(){

print ("show");

DialogMgr.ShowDialog(CharacterSelectPrefab, OnCharacterSelectOk, OnCharacterSelectCancel, "Character Select", "Buy ??");

}


void OnCharacterSelectOk(){

print ("Select ok");

}

void OnCharacterSelectCancel(){

print ("Select Cancel");

}

//////////////////////////////////////////////////////////

using UnityEngine;

using System.Collections;


public class DialogMgr : MonoBehaviour{

static GameObject DialogPrefab;

static GameObject DialogParent;

static GameObject DialogPurchasePrefab;

static GameObject DialogPurchaseParent;

static string title = "Game Purchase";

static string message = "";

//static GameObject AddressDialogPrefab;

//static GameObject AddressDialogParent;

public static void ShowDialog(GameObject prefab, Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction,

string title, string message){

if(null == DialogParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

DialogParent = cam.gameObject;

}

GameObject obj = null;

if (prefab == null) {

Debug.LogError("prefab is null");

return;

}

else {

obj = NGUITools.AddChild(DialogParent, prefab);

obj.transform.position = new Vector3(0.0f, 0.0f, -1.5f);

}

Dialog dlg = obj.GetComponent<Dialog>();

dlg.Title.text = title;

dlg.Message.text = message;

dlg.eventButtonOk += okFunction;

dlg.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj, 100);

}

/*

public static void ShowAddressDialog( Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction){

if(null == AddressDialogParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

AddressDialogParent = cam.gameObject;

}

if(null == AddressDialogPrefab){

DialogPrefab = Resources.Load("Prefabs/AddressBody") as GameObject;

}

GameObject obj = NGUITools.AddChild(AddressDialogParent, AddressDialogPrefab);

Dialog dlg = obj.GetComponent<Dialog>();

//dlg.Title.text = title;

//dlg.Message.text = message;

dlg.eventButtonOk += okFunction;

dlg.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj, 100);

}

*/

public static void ShowPurchaseDialog(Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction){

if(null == DialogPurchaseParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

DialogPurchaseParent = cam.gameObject;

}

if(null == DialogPurchasePrefab){

DialogPurchasePrefab = Resources.Load("Prefabs/Player_BackGround") as GameObject;

}

GameObject obj1 = NGUITools.AddChild(DialogPurchaseParent, DialogPurchasePrefab);

Dialog dlgPurchase = obj1.GetComponent<Dialog>();

dlgPurchase.Title.text = title;

dlgPurchase.Message.text = message;

dlgPurchase.eventButtonOk += okFunction;

dlgPurchase.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj1, 300);

}

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

}


Dummy.prefab


https://www.mixamo.com

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

Dialog() 다이아로그  (0) 2014.11.10
더미와 다이어로그  (0) 2014.11.10
파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21
ITWEEN PATH탐지. 쉐이크, 좌우이동  (0) 2014.07.01
코루틴 예제  (0) 2014.07.01

using UnityEngine;

using System.Collections;


/*

 * 1

public class Player : MonoBehaviour {

public float Speed = 1;

public GameObject FirePrefab;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

float h = Input.GetAxis("Horizontal");

float v = Input.GetAxis("Vertical");

transform.Translate(Speed * new Vector3(h, 0, v));

if(Input.GetButtonUp("Fire1")){

GameObject particle = Instantiate(FirePrefab, transform.position, Quaternion.identity) as GameObject;

float duration = particle.GetComponent<ParticleSystem>().duration;

Destroy(particle, duration);

}

}

}

*/


 //2

public class Player : MonoBehaviour {

public GameObject FireParticle;

public int Speed;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

if(Input.GetKeyDown(KeyCode.Space)){

FireParticle.SetActive(true);

float duration = FireParticle.GetComponent<ParticleSystem>().duration;

Invoke("sleep" , duration);

}

}

void sleep(){

FireParticle.SetActive(false);

}

}


 

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

더미와 다이어로그  (0) 2014.11.10
캐릭터,리그 ,애니메이터  (0) 2014.07.21
ITWEEN PATH탐지. 쉐이크, 좌우이동  (0) 2014.07.01
코루틴 예제  (0) 2014.07.01
하스스톤 디딤돌  (0) 2014.07.01


using UnityEngine;

using System.Collections;


public class TestPath : MonoBehaviour {

public Transform[] Path;

public float duration = 0.02f;

float percent = 0;

float startTime;

// Use this for initialization

void Start () {

startTime = Time.time;

/* put on path

Vector3[] points = new Vector3[Path.Length];

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

points[i] = Path[i].position;

}

*/

}

// Update is called once per frame

void Update () {

//percent = Mathf.Clamp01(Time.time - startTime) / duration;

percent = (Time.time - startTime) / duration;

iTween.PutOnPath(gameObject, Path, percent % 1);

Vector3 next = iTween.PointOnPath(Path, (percent + 0.1f) % 1);

//transform.LookAt(next);

Vector3 forward = next - transform.position;

transform.rotation = Quaternion.LookRotation(forward);

}

}


TestShake.cs 흔들어 주세요..


using UnityEngine;

using System.Collections;


public class TestPath : MonoBehaviour {

public Transform[] Path;

public float duration = 0.02f;

float percent = 0;

float startTime;

// Use this for initialization

void Start () {

startTime = Time.time;

/* put on path

Vector3[] points = new Vector3[Path.Length];

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

points[i] = Path[i].position;

}

*/

}

// Update is called once per frame

void Update () {

//percent = Mathf.Clamp01(Time.time - startTime) / duration;

percent = (Time.time - startTime) / duration;

iTween.PutOnPath(gameObject, Path, percent % 1);

Vector3 next = iTween.PointOnPath(Path, (percent + 0.1f) % 1);

//transform.LookAt(next);

Vector3 forward = next - transform.position;

transform.rotation = Quaternion.LookRotation(forward);

}

}


TestTween.cs 좌우로 흔들고 마지막에 크게.

using UnityEngine;

using System.Collections;


public class TestTween : MonoBehaviour {

bool isForward;

void Update () {

if(Input.GetMouseButton(0)){

if(isForward){

iTween.MoveTo(gameObject, new Vector3(3, 0, 0), 1.0f);

}

else{

//1)

//iTween.MoveTo(gameObject, new Vector3(-3, 0, 0), 1.0f);

//2)

//iTween.MoveTo(gameObject, iTween.Hash("x", -3, "easyType", "easeInCirc" , "time", 1.0f));

//3)

Hashtable table = new Hashtable();

table.Add("x", -3);

table.Add("easyType", iTween.EaseType.easeInElastic);

table.Add("time", 1.0f);

table.Add ("oncompletetarget", gameObject);

table.Add("oncomplete", "OnCompleteMove");

iTween.MoveTo(gameObject, table);

}

isForward = !isForward;

}

}

void OnCompleteMove(){

iTween.PunchScale(gameObject,1.5f * Vector3.one, 0.5f);

}

}



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

캐릭터,리그 ,애니메이터  (0) 2014.07.21
파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21
코루틴 예제  (0) 2014.07.01
하스스톤 디딤돌  (0) 2014.07.01
SkinnedMeshRenderer  (0) 2014.06.27

.81640625using UnityEngine;

using System.Collections;


public class TestCoroutine : MonoBehaviour {

public float moveSpeed = 1;

public Vector3[] path;

// Use this for initialization

void Start () {

//StartCoroutine(MoveToPosition(new Vector3(3, 0, 0)));

StartCoroutine(MoveOnPath(true));

}

IEnumerator MoveCube1(){

transform.Translate(2, 0, 0);

yield return new WaitForSeconds(1.0f);

transform.Translate(0, 2, 0);

yield return new WaitForSeconds(2.0f);

transform.Translate(2, 2, 0);

yield return new WaitForSeconds(3.0f);

}

IEnumerator MoveCube2(){

int count = 3;

while(Time.time < 2 && count > 0){

yield return new WaitForSeconds(0.01f);

transform.Translate(2f, 0, 0);

count -= 1;

}

}

IEnumerator MoveCube3(){

while(Time.time < 3)

{

transform.Translate(0.05f, 0, 0);

yield return 0;

}

}

IEnumerator MoveToPosition(Vector3 target)

{

while((transform.position - target).sqrMagnitude > 0.01f)

{

transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime);

yield return 0;

}

}

IEnumerator MoveOnPath(bool loop)

{

foreach(Vector3 point in path)

yield return StartCoroutine(MoveToPosition(point));

}

// Update is called once per frame

void Update () {

}

}



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

파티클 1번과 2번 2번을 주로 애용  (0) 2014.07.21
ITWEEN PATH탐지. 쉐이크, 좌우이동  (0) 2014.07.01
하스스톤 디딤돌  (0) 2014.07.01
SkinnedMeshRenderer  (0) 2014.06.27
GUI 씬 전환  (0) 2014.06.23

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

+ Recent posts