using UnityEngine;

using System.Collections;


public class HPBar : MonoBehaviour {

public Texture ForegroundTexture;

public Texture BackgroundTexture;

public Texture2D DamageTexture;  //use 2D UI and change color


void OnGUI()  //draw picture method

{

Rect rect = new Rect(10,6,Screen.width/2-20,BackgroundTexture.height);  //(x,y,width,height)

GUI.DrawTexture(rect,BackgroundTexture);

float hp = PlayerCtrl.hp;

rect.width *= hp;

GUI.color = DamageTexture.GetPixelBilinear(hp,0.5f);   //read color value

GUI.DrawTexture(rect,ForegroundTexture);

GUI.color = Color.white;

}

}


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

All Script in ThirdPersonShooingGame  (0) 2013.08.23
plane size 동적할당  (0) 2013.08.21
시계바  (0) 2013.08.20
PaddleGame  (0) 2013.08.15
MonsterCtrl.cs  (0) 2013.08.12

 

 #pragma strict


var isPaused : boolean = false;
var startTime : float;
var timeRemaining : float;
var percent:float;
var clockBG:Texture2D;
var clockFG:Texture2D;
var clockFGMaxWidth:float;  //initial value of bar;

function Start () {
 startTime = 120.0;
 clockFGMaxWidth = clockFG.width;
}

function Update () {
 if(!isPaused)
 {
  DoCountDown();
 }
}

function DoCountDown() {

 timeRemaining = startTime - Time.time;
 percent = timeRemaining/startTime * 100;
 if(timeRemaining < 0)
 {
  timeRemaining = 0;
  isPaused = true;
  TimeIsUp();
 }
 
 /*if(timeRemaining < 0)
 {
  timeRemaining = 0;
  isPaused = true;
  TimeIsUp();
 }
 */
 ShowTime();
 Debug.Log("Time remaining = " + timeRemaining);
}

function PauseClock(){

}

function UnpauseClock(){
 isPaused = false;
}

function ShowTime(){

 var minutes : int;
 var seconds : int;
 var timeStr : String;
 
 minutes = timeRemaining/60;
 seconds = timeRemaining%60;
 timeStr = minutes.ToString() + ":";
 timeStr += seconds.ToString("D2");
 guiText.text = timeStr;
}

function TimeIsUp(){
 Debug.Log("Time is up");
}


function OnGUI()
{
 var newBarWidth:float = (percent/100) * clockFGMaxWidth;
 var gap:int = 20;
 GUI.BeginGroup(new Rect(Screen.width - clockBG.width - gap,gap,clockBG.width, clockBG.height));
 GUI.DrawTexture(Rect(0,0,clockBG.width, clockBG.height),clockBG);
 GUI.BeginGroup(new Rect(5,6,newBarWidth,clockFG.height));
 GUI.DrawTexture(Rect(0,0,clockFG.width, clockFG.height),clockFG);
 GUI.EndGroup();
 GUI.EndGroup();
}

 

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

plane size 동적할당  (0) 2013.08.21
HPBar  (0) 2013.08.20
PaddleGame  (0) 2013.08.15
MonsterCtrl.cs  (0) 2013.08.12
메카님방식  (0) 2013.08.12

 

 

 

 #pragma strict

function Start () {

}

var smooth = 5.0;
var tiltAngle = 30.0;

function Update () {
 var halfW:float = Screen.width/2;
 transform.position.x = (Input.mousePosition.x - halfW) / (halfW);
 
 var halfH:float = Screen.height/3;
 transform.position.y = (Input.mousePosition.y - halfH) / (halfH);
 
 // 회전값을 향해서 부드럽게 기울임.
 var tiltAroundZ = Input.GetAxis("Mouse X") * tiltAngle * 1;
 var tiltAroundX = Input.GetAxis("Mouse Y") * tiltAngle * -1;
 var target = Quaternion.Euler ( tiltAroundX, 0, tiltAroundZ);
 
 
 // 타겟 회전값을 향해 변화하는 강도를 약화시킨다.
 transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
 
 
 //Debug.Log((Input.mousePosition.x - halfW)/halfW);

}

 

 

 

 

 

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

HPBar  (0) 2013.08.20
시계바  (0) 2013.08.20
MonsterCtrl.cs  (0) 2013.08.12
메카님방식  (0) 2013.08.12
BulletCtrl.cs  (0) 2013.08.07

using UnityEngine;

using System.Collections;


[RequireComponent (typeof(AudioSource))]     //i don't need to Input Audio sources again in component.

public class MonsterCtrl : MonoBehaviour {

public Transform PlayerTr;

public Transform MonsterTr;

public NavMeshAgent nv;

public float TraceTime = 0.5f;

public Animator anim;

// Use this for initialization

void Start () {

PlayerTr = GameObject.Find ("Player").GetComponent<Transform>();

MonsterTr = this.gameObject.GetComponent<Transform>();

nv = GetComponent<NavMeshAgent>();

nv.destination = PlayerTr.position;   //start to trace where player's position.

anim = GetComponent<Animator>();

}

// Update is called once per frame

void Update () {

if(Vector3.Distance(MonsterTr.position,PlayerTr.position) < 2.0f)

{

nv.Stop();//stop trace~!!!!

anim.SetBool("IsAttack",true);

anim.SetBool("IsTrace",false);

}else

{

if(Time.time > TraceTime)

{

nv.destination = PlayerTr.position;

TraceTime = Time.time + 0.5f;

}

nv.Resume();   //restart to trace~!!!!

anim.SetBool("IsAttack",false);

anim.SetBool("IsTrace",true);

}

}

}


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

시계바  (0) 2013.08.20
PaddleGame  (0) 2013.08.15
메카님방식  (0) 2013.08.12
BulletCtrl.cs  (0) 2013.08.07
miniMap  (0) 2013.08.07

+ Recent posts