public class youxi : MonoBehaviour {
public Rect r1=new Rect(250,100,400,200);
public Rect r2=new Rect(250,330,400,200);
// public Texture t1;
// public Texture t2;
// public Texture t3;
public Texture[] txtures;
public int computercp;
public int playercp;
public string result;
public bool showtime=true;
public float maxtime=1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (showtime) {
computerShow ();
} else {
maxtime-=Time.deltaTime;
if(maxtime<0){
showtime=true;
maxtime = 1;
}
}
}
void computerShow()
{
if(computercp<2){
computercp++;
}else {
computercp=0;
}
}
void OnGUI(){
GUI.Label (new Rect(410,20,100,30),result);
r1=GUI.Window (0, r1, windFan1, "computer vs player");
r2=GUI.Window(1,r2,winFand2,"player");
if (GUI.Button (new Rect (700, 0, 100, 30), "返回")) { //这里是跳转到别的地方
Application.LoadLevel("chang1");
}
if (GUI.Button (new Rect (700, 100, 100, 30), "wu liao")) {
Application.LoadLevel("chang3");
}
}
void windFan1(int Id){
GUI.Box(new Rect (30,30,150,150),txtures[computercp]);
GUI.Box(new Rect (220,30,150,150),txtures[playercp]);
GUI.DragWindow (new Rect (0, 0, 450, 30));
}
void winFand2(int Id){
if (GUI.Button (new Rect (30, 30, 100, 100), txtures [0])) {
playercp=0;
computerchupai();
panding();
}
if (GUI.Button (new Rect (150, 30, 100, 100), txtures [1])) {
playercp=1;
computerchupai();
panding();
}
if (GUI.Button (new Rect (270, 30, 100, 100), txtures [2])) {
playercp=2;
computerchupai();
panding();
}
GUI.DragWindow (new Rect (0, 0, 450, 30));
}
void computerchupai(){
showtime = false;
computercp = Random.Range (0, 3);
}
void panding(){
if (computercp - playercp == 0) {
result = "好可惜,平局";
} else if (computercp - playercp== -1||computercp - playercp == 2) {
result ="好遗憾,再来一次";
} else if(computercp - playercp == 1||computercp - playercp == -2){
result ="真棒,你赢了";
}
}
}
public Rect r1=new Rect(250,100,400,200);
public Rect r2=new Rect(250,330,400,200);
// public Texture t1;
// public Texture t2;
// public Texture t3;
public Texture[] txtures;
public int computercp;
public int playercp;
public string result;
public bool showtime=true;
public float maxtime=1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (showtime) {
computerShow ();
} else {
maxtime-=Time.deltaTime;
if(maxtime<0){
showtime=true;
maxtime = 1;
}
}
}
void computerShow()
{
if(computercp<2){
computercp++;
}else {
computercp=0;
}
}
void OnGUI(){
GUI.Label (new Rect(410,20,100,30),result);
r1=GUI.Window (0, r1, windFan1, "computer vs player");
r2=GUI.Window(1,r2,winFand2,"player");
if (GUI.Button (new Rect (700, 0, 100, 30), "返回")) { //这里是跳转到别的地方
Application.LoadLevel("chang1");
}
if (GUI.Button (new Rect (700, 100, 100, 30), "wu liao")) {
Application.LoadLevel("chang3");
}
}
void windFan1(int Id){
GUI.Box(new Rect (30,30,150,150),txtures[computercp]);
GUI.Box(new Rect (220,30,150,150),txtures[playercp]);
GUI.DragWindow (new Rect (0, 0, 450, 30));
}
void winFand2(int Id){
if (GUI.Button (new Rect (30, 30, 100, 100), txtures [0])) {
playercp=0;
computerchupai();
panding();
}
if (GUI.Button (new Rect (150, 30, 100, 100), txtures [1])) {
playercp=1;
computerchupai();
panding();
}
if (GUI.Button (new Rect (270, 30, 100, 100), txtures [2])) {
playercp=2;
computerchupai();
panding();
}
GUI.DragWindow (new Rect (0, 0, 450, 30));
}
void computerchupai(){
showtime = false;
computercp = Random.Range (0, 3);
}
void panding(){
if (computercp - playercp == 0) {
result = "好可惜,平局";
} else if (computercp - playercp== -1||computercp - playercp == 2) {
result ="好遗憾,再来一次";
} else if(computercp - playercp == 1||computercp - playercp == -2){
result ="真棒,你赢了";
}
}
}