連結
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Threading;
public class buttonMsg
{
//價值
private int price;
//被下注次數
private int bettingCount;
//當前下注金額
private int currentPrice;
public buttonMsg(int _price)
{
price = _price;
bettingCount = 0;
}
//回傳價值
public int getPrice()
{
return price;
}
//下注
public void betting()
{
bettingCount++;
}
//回傳下注數
public int getBettingCount()
{
return bettingCount;
}
//回傳下注金額
public int getCurrentPrice()
{
currentPrice = bettingCount * price;
return currentPrice;
}
//重置
public void reSet()
{
bettingCount = 0;
}
}
public class button : MonoBehaviour
{
Text chipsText;
Text bettingText;
Text[] bettingCountText = new Text[10];
int myChips = 100;
int myBetting = 0;
int[] imgPrice = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 10, 30, 20, 10, 70, 60, 50, 40, 30, 20 };
buttonMsg[] myBut = new buttonMsg[10];
bool roundBool = false;
float time = 0;
int round1Num = 0;
int round2Num = 0;
int round3Num = 0;
int randNum;
// Use this for initialization
void Start()
{
for (int i = 0; i < 10; i++)
{
int butNum = ((i + 1) * 10);
string path;
path = string.Format("bettingCount{0}", butNum);
bettingCountText[i] = GameObject.Find(path).GetComponent<Text>();
myBut[i] = new buttonMsg(butNum);
}
chipsText = GameObject.Find("Canvas/chips").GetComponent<Text>();
bettingText = GameObject.Find("Canvas/betting").GetComponent<Text>();
chipsText.text = myChips.ToString();
bettingText.text = myBetting.ToString();
}
// Update is called once per frame
void Update()
{
time += Time.deltaTime;
if (roundBool == true)
{
if (time >= 0.01 && round1Num <= 23)
{
round(round1Num);
time = 0;
round1Num++;
}
if (round1Num == 24 && time >= 0.03 && round2Num <= 23)
{
round(round2Num);
time = 0;
round2Num++;
}
if (round2Num == 24 && time >= 0.05 && round3Num <= randNum)
{
round(round3Num);
time = 0;
round3Num++;
}
}
if (round3Num == randNum + 1)
randProfit();
chipsText.text = myChips.ToString();
bettingText.text = myBetting.ToString();
for (int i = 0; i < 10; i++)
{
bettingCountText[i].text = myBut[i].getBettingCount().ToString();
}
}
void round(int _imgNum)
{
string imgNum;
Image img;
imgNum = string.Format("Image{0}", _imgNum);
img = GameObject.Find(imgNum).GetComponent<Image>();
img.color = UnityEngine.Color.red;
if (_imgNum == 23)
{
img.color = UnityEngine.Color.white;
}
if (_imgNum != 0)
{
imgNum = string.Format("Image{0}", (_imgNum - 1));
img = GameObject.Find(imgNum).GetComponent<Image>();
img.color = UnityEngine.Color.white;
}
}
void randProfit()
{
string imgNums = string.Format("Image{0}", randNum);
Image img = GameObject.Find(imgNums).GetComponent<Image>();
img.color = UnityEngine.Color.red;
for (int i = 0; i < 10; i++)
{
if (myBut[i].getPrice() == imgPrice[randNum])
{
myChips += (myBut[i].getCurrentPrice() * 2);
}
}
myBetting = 0;
for (int i = 0; i < 10; i++) myBut[i].reSet();
roundBool = false;
round1Num = 0;
round2Num = 0;
round3Num = 0;
}
public void start()
{
time = 0.1f;
roundBool = true;
randNum = Random.Range(0, 23);
}
public void reset()
{
myChips = 100;
myBetting = 0;
for (int i = 0; i < 10; i++)
{
myBut[i].reSet();
}
}
public void bettingButton(int _butNum)
{
int bettingTemp = myChips - myBut[_butNum].getPrice();
if (bettingTemp >= 0)
{
myBetting += myBut[_butNum].getPrice();
myChips = bettingTemp;
myBut[_butNum].betting();
}
}
}
2016年12月29日 星期四
2016年12月8日 星期四
剪刀石頭佈
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
void Start (){
}
void Update () {
}
public void click(){
int randNum = Random.Range(1, 4);
Text inform = GameObject.Find("Canvas/Panel/Text").GetComponent<Text>();
inform.text = randNum.ToString();
Image img = GameObject.Find("Canvas/Panel/Image").GetComponent<Image>();
img.sprite = Resources.Load<Sprite>("image/" + randNum) as Sprite;
}
}
球跟方塊(無材質)
using System.Collections;
public class Player : MonoBehaviour
{
public GameObject obj_Player;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
obj_Player = GameObject.Find("Sphere");
if (Input.GetKeyDown(KeyCode.A))
{
obj_Player.transform.position += new Vector3(-0.5f, 0, 0);
}
else if (Input.GetKeyDown(KeyCode.D))
{
obj_Player.transform.position += new Vector3(0.5f, 0, 0);
}
else if (Input.GetKeyDown(KeyCode.W))
{
obj_Player.transform.position += new Vector3(0, 0, 0.5f);
}
else if (Input.GetKeyDown(KeyCode.S))
{
obj_Player.transform.position += new Vector3(0, 0, -0.5f);
}
}
}
球跟方塊(有材質)
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public GameObject obj_Player;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
obj_Player = GameObject.Find("Sphere");
if (Input.GetKeyDown(KeyCode.A))
{
obj_Player.transform.position += new Vector3(-0.5f, 0, 0);
}
else if (Input.GetKeyDown(KeyCode.D))
{
obj_Player.transform.position += new Vector3(0.5f, 0, 0);
}
else if (Input.GetKeyDown(KeyCode.W))
{
obj_Player.transform.position += new Vector3(0, 0, 0.5f);
}
else if (Input.GetKeyDown(KeyCode.S))
{
obj_Player.transform.position += new Vector3(0, 0, -0.5f);
}
}
}
人物
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public GameObject obj_Player;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
obj_Player = GameObject.Find("HuMan");
if (Input.GetKeyDown(KeyCode.A))
{
obj_Player.transform.position += new Vector3(-0.1f, 0, 0);
}
else if (Input.GetKeyDown(KeyCode.D))
{
obj_Player.transform.position += new Vector3(0.1f, 0, 0);
}
else if (Input.GetKeyDown(KeyCode.W))
{
obj_Player.transform.position += new Vector3(0, 0, 0.1f);
}
else if (Input.GetKeyDown(KeyCode.S))
{
obj_Player.transform.position += new Vector3(0, 0, -0.1f);
}
}
}
三原色
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
myfun();
}
public void myfun()
{
float num = 0;
num = GameObject.Find("Slider").GetComponent<Slider>().value;
Text mytxt = GameObject.Find("Text").GetComponent<Text>();
mytxt.text = num.ToString();
Image img = GameObject.Find("Image").GetComponent<Image>();
img.color = new Color(num,0.0F,0.0F,1.0F);
float num2 = 0;
num2 = GameObject.Find("Slider2").GetComponent<Slider>().value;
Text mytxt2 = GameObject.Find("Text2").GetComponent<Text>();
mytxt2.text = num2.ToString();
Image img2 = GameObject.Find("Image2").GetComponent<Image>();
img2.color = new Color(0.0F,num2,0.0F,1.0F);
float num3 = 0;
num3 = GameObject.Find("Slider3").GetComponent<Slider>().value;
Text mytxt3 = GameObject.Find("Text3").GetComponent<Text>();
mytxt3.text = num3.ToString();
Image img3 = GameObject.Find("Image3").GetComponent<Image>();
img3.color = new Color(0.0F,0.0F,num3,1.0F);
Image img4 = GameObject.Find("Image4").GetComponent<Image>();
img4.color = new Color(num,num2,num3,1.0F);
}
}
倒數計時器
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public bool timerOn = false;
float time;
// Use this for initialization
void Start()
{
time = 3;
timerOn = false;
}
// Update is called once per frame
void Update()
{
Text mytxt3 = GameObject.Find("Canvas/Panel/Text3").GetComponent<Text>();
if (timerOn == true&& time>0)
{
time = time- Time.deltaTime;
mytxt3.text = time.ToString();
}
if(timerOn == true && time < 0)
{
time = 0;
mytxt3.text = time.ToString();
}
Text mytxt1 = GameObject.Find("Canvas/Panel/Text").GetComponent<Text>();
mytxt1.text = System.DateTime.Now.ToString("MM/dd/yyyy");
Text mytxt = GameObject.Find("Canvas/Panel/Text2").GetComponent<Text>();
mytxt.text = System.DateTime.Now.ToString("hh:mm:ss");
}
public void startB()
{
timerOn = true;
}
public void stopB()
{
if (time == 0)
{
Text mytxt3 = GameObject.Find("Canvas/Panel/Text3").GetComponent<Text>();
time = 3;
mytxt3.text = time.ToString();
}
timerOn = false;
}
}
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public bool timerOn = false;
float time;
// Use this for initialization
void Start()
{
time = 3;
timerOn = false;
}
// Update is called once per frame
void Update()
{
Text mytxt3 = GameObject.Find("Canvas/Panel/Text3").GetComponent<Text>();
if (timerOn == true&& time>0)
{
time = time- Time.deltaTime;
mytxt3.text = time.ToString();
}
if(timerOn == true && time < 0)
{
time = 0;
mytxt3.text = time.ToString();
}
Text mytxt1 = GameObject.Find("Canvas/Panel/Text").GetComponent<Text>();
mytxt1.text = System.DateTime.Now.ToString("MM/dd/yyyy");
Text mytxt = GameObject.Find("Canvas/Panel/Text2").GetComponent<Text>();
mytxt.text = System.DateTime.Now.ToString("hh:mm:ss");
}
public void startB()
{
timerOn = true;
}
public void stopB()
{
if (time == 0)
{
Text mytxt3 = GameObject.Find("Canvas/Panel/Text3").GetComponent<Text>();
time = 3;
mytxt3.text = time.ToString();
}
timerOn = false;
}
}
訂閱:
文章 (Atom)