Unity3d script: C # timing Class script

Source: Internet
Author: User

Unity3d script: C # timing Class script
Unity3d More Resources Tutorials free download, group 153442627
Using Unityengine;
Using System.Collections;
<summary>
C # timer adapted from the JS timer of Jeff ' Psychicparrot ' Murray
</summary>
public class Timer:monobehaviour {
private float timeelapsed = 0.0f;
private float currenttime = 0.0f;
private float lasttime = 0.0f;
private float cdtime = 0.0f;
private float timescalefactor = 1.0f;
private bool istimerrunning;
private bool Donecallback;
private float parsetime;
Private Gameobject callback;
private float Ahour;
private float Aminute;
private float Asecond;
private float Amillis;
private string seconds;
private string minutes;
private string Hour;
private string Mills;
private string timestring;
void Update ()
{
Timeelapsed=time.time-lasttime;
if (istimerrunning) {
Currenttime+=timeelapsed*timescalefactor;
}
Lasttime=time.time;
}
public void Starttimer ()
{
Istimerrunning=true;
Donecallback=false;
Lasttime=time.time;
}
public void Stoptimer ()
{
Istimerrunning=false;
}
public void Resettimer ()
{
Donecallback=false;
timeelapsed=0.0f;
lasttime=0.0f;
currenttime=0.0f;
Lasttime=time.time;
}
public void Setcountdowntime (float aTime)
{
Cdtime=atime;
}
public void Setcallback (Gameobject aRef)
{
Callback=aref;
Donecallback=false;
}
public float GetTime ()
{
return currenttime;
}
public string getformattedtime (int returntype)
{
if (cdtime>0) {
If a countdown time has been set, we parse the reverse time value
Parsetime=cdtime-currenttime;
if (parsetime<0) {
if (!donecallback) {
Sound the ALARM!!!!! WE hit 0!
Callback. SendMessage ("Alarmdone");
Set our Donecallback flag so as not to repeat call Alarmdone ()
Donecallback=true;
}
parsetime=0;
}
} else {
If no countdown time has been set, we just parse the regular time
Parsetime=currenttime;
}
Grab hours
Ahour = parsetime/3600;
ahour=ahour%24;
Grab minutes
AMINUTE=PARSETIME/60;
aminute=aminute%60;
Grab seconds
asecond=parsetime%60;
Grab milliseconds
Amillis= (parsetime*100)%100;
format string into mm:ss:mm
Seconds=mathf.round (Asecond). ToString ();
if (seconds. LENGTH&LT;2)
seconds= "0" +seconds;
Minutes=mathf.round (Aminute). ToString ();
if (minutes. LENGTH&LT;2)
minutes= "0" +minutes;
Hour=mathf.round (Ahour). ToString ();
if (hour. LENGTH&LT;2)
Hour= "0" +hour;
Mills=mathf.round (Amillis). ToString ();
if (Mills. LENGTH&LT;2)
mills= "0" +mills;
Switch (returntype) {
Case 1:
timestring=minutes+ ":" +seconds+ ":" +mills;
Break
Case 2:
timestring=minutes+ ":" +seconds;
Break
Default
timestring=hour+ ":" +minutes+ ":" +seconds+ ":" +mills;
Break
}
return timestring;
}
public float GetHours ()
{
if (cdtime>0) {
If a countdown time has been set, we parse the reverse time value
Parsetime=cdtime-currenttime;
if (parsetime<0) {
parsetime=0;
}
} else {
If no countdown time has been set, we just parse the regular time
Parsetime=currenttime;
}
Grab hours
Ahour = parsetime/3600;
return ahour;
}
public float getminutes ()
{
if (cdtime>0) {
If a countdown time has been set, we parse the reverse time value
Parsetime=cdtime-currenttime;
if (parsetime<0) {
parsetime=0;
}
} else {
If no countdown time has been set, we just parse the regular time
Parsetime=currenttime;
}
Grab minutes
AMINUTE=PARSETIME/60;
aminute=aminute%60;
return aminute;
}
public float getseconds ()
{
if (cdtime>0) {
If a countdown time has been set, we parse the reverse time value
Parsetime=cdtime-currenttime;
if (parsetime<0) {
parsetime=0;
}
} else {
If no countdown time has been set, we just parse the regular time
Parsetime=currenttime;
}
Grab seconds
asecond=parsetime%60;
return asecond;
}
public int Getclocktimehour ()
{
int atime=system.datetime.now.hour;
return aTime;
}
public int Getclocktimeminute ()
{
int Atime=system.datetime.now.minute;
return aTime;
}
public int getclocktimeseconds ()
{
int Atime=system.datetime.now.second;
return aTime;
}
public string getclockformattedtime (int returntype)
{
int Ahour =system.datetime.now.hour;
int Aminute =system.datetime.now.minute;
int Asecond =system.datetime.now.second;
int Amillis =system.datetime.now.millisecond;
format string into mm:ss:mm
Seconds=mathf.round (Asecond). ToString ();
if (seconds. LENGTH&LT;2)
seconds= "0" +seconds;
Minutes=mathf.round (Aminute). ToString ();
if (minutes. LENGTH&LT;2)
minutes= "0" +minutes;
Hour=mathf.round (Ahour). ToString ();
if (hour. LENGTH&LT;2)
Hour= "0" +hour;
Mills=mathf.round (Amillis). ToString ();
if (Mills. LENGTH&LT;2)
mills= "0" +mills;
if (Mills. LENGTH&GT;2)
Mills=mills. Substring (0,2);
Switch (returntype) {
Case 1:
timestring=minutes+ ":" +seconds+ ":" +mills;
Break
Case 2:
timestring=minutes+ ":" +seconds;
Break
Default
timestring=hour+ ":" +minutes+ ":" +seconds+ ":" +mills;
Break
}
return timestring;
}
}
Unity3d script: Edge Highlight Script
Posted on February 16, 2013 by U3d/unity3d script/plugin/BE onlookers 240 times
Shader shader, Edge highlight, just one shader file, directly available.
Shader "Example/rim" {
Properties {
_maintex ("Texture", 2D) = "White" {}
_bumpmap ("BumpMap", 2D) = "Bump" {}
_rimcolor ("Rim color", color) = (0.26,0.19,0.16,0.0)
_rimpower ("Rim Power", Range (0.5,8.0)) = 3.0
}
Subshader {
Tags {"Rendertype" = "Opaque"}
Cgprogram
#pragma surface surf Lambert
struct Input {
FLOAT2 Uv_maintex;
FLOAT2 Uv_bumpmap;
FLOAT3 Viewdir;
};
Sampler2d _maintex;
Sampler2d _bumpmap;
FLOAT4 _rimcolor;
float _rimpower;
void Surf (Input in, InOut surfaceoutput o) {
O.albedo = tex2d (_maintex, In.uv_maintex). RGB;
O.normal = Unpacknormal (tex2d (_bumpmap, In.uv_bumpmap));
Half rim = 1.0-saturate (dot (normalize (in.viewdir), o.normal));
o.emission = _rimcolor.rgb * POW (rim, _rimpower);
}
Endcg
}
Fallback "Diffuse"
}

Unity3d script: C # timing Class script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.