using UnityEngine;

using System.Collections;


public class PlayCtrl : MonoBehaviour {

[System.Serializable]   //it makes that i can use c#

public class Anim

{

public AnimationClip Idle;

public AnimationClip runForward;

public AnimationClip runBackward;

public AnimationClip runRight;

public AnimationClip runLeft;

}


public Anim anim;

public Animation aniBody;

public float Speed = 10.0f;

public GameObject BulletPrefab;

public Transform firepos;     //i can Input other objects.


// Use this for initialization

void Start () 

{

aniBody.clip = anim.Idle;

aniBody.Play();

}

// Update is called once per frame

void Update () {

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

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

transform.Translate(Vector3.right * h * Speed * Time.deltaTime);

transform.Translate(Vector3.forward * v * Speed * Time.smoothDeltaTime);  // i need to cheak!

if(h > 0.1f)

{

aniBody.CrossFade(anim.runRight.name,0.3f);

    }

else if(h < -0.1f)

{

aniBody.CrossFade(anim.runLeft.name,0.3f);

    }

else if(v > 0.1f)

{

aniBody.CrossFade(anim.runForward.name,0.3f);

    }

else if(v < -0.1f)

{

aniBody.CrossFade(anim.runBackward.name,0.3f);

    }

else{

aniBody.CrossFade(anim.Idle.name,0.3f);

}

// if(Input.GetMouseButtonDown(0))  --> when I click Left mouse

if(Input.GetMouseButtonDown(0))

{

StartCoroutine("Fire");    //method name is Fire~ ~!! it's just name.

//multi Thread

}

}

IEnumerator Fire()   //if return type is IEnumerator.. this method is multi thread..

{

GameObject newBullet = (GameObject)Instantiate(BulletPrefab,firepos.position,Quaternion.identity);

//Quaternion.Euler(x,y,z);    rotation...

Destroy(newBullet, 3.0f);      //after i fired bullet..

yield return null;

}

}


'유니티3D > 예제' 카테고리의 다른 글

BulletCtrl.cs  (0) 2013.08.07
miniMap  (0) 2013.08.07
Bullet  (0) 2013.08.06
MyGizmo.cs  (0) 2013.08.06
Spark.cs  (0) 2013.08.06

+ Recent posts