void init() //initialize { t1 = gameObject.AddComponent <Timer>(); t2 = gameObject.AddComponent <Timer> (); t3 = gameObject.AddComponent <Timer> (); t4 = gameObject.AddComponent <Timer> (); animator = GetComponent <Animator> (); body = GetComponent <Rigidbody> (); nowHp = hp; PlayerSkill1Obj.SetActive(false); fakeSummonObj.SetActive(false); PlayerSkill2Obj.SetActive(false); r = gameObject.GetComponent <SpriteRenderer>(); //绑定到SpriteRenderer上 //skill3 //exp&level level = 1; setExperience(); isAtt = false; agent = GetComponent <NavMeshAgent> (); skill3_isOnce = true; gamestate = GameState.start; fairy = GameObject.FindObjectOfType <Fairy> (); fairy.changeTalkState((int)gamestate); tSkill1 = gameObject.AddComponent <Timer> (); isOpen = false; }
void skill() //skill and summon { foreach (char c in Input.inputString) { switch (c) { //技能 case ' ': //普攻 animator.SetTrigger("attack"); //攻擊動畫 isAtt = true; break; case 'Q': case 'q': if (!isSkill && !isSkill3) //如果沒再用其他技能的時候 { if (tSkill1.timer(skill1CD)) { //cd PlayerSkill1Obj.SetActive(true); isSkill = true; } } break; case 'W': case 'w': if (!isSkill && !isSkill3) { isSkill = true; PlayerSkill2Obj.SetActive(true); animator.SetBool("isSkill2", true); } break; /*case 'E': * case 'e': * if (!isSkill) { * //check power?? * //check cd * //isSkill = true; * //skillNo3 (); * Debug.Log ("skill 3"); * } * break;*/ //召喚獸 case 'A': //NO0 case 'a': if (checkSummon(0)) { float sumCD = summons [0].GetComponent <Summon> ().summonCD; if (t1.timer(sumCD)) { int sumCost = summons [0].GetComponent <Summon> ().summonCost; if (checkPower(sumCost)) { fakeSummonObj.GetComponent <SpriteRenderer>().sprite = summons [0].GetComponent <Summon>().summonIcon; //set sprite fakeSummonObj.GetComponent <FakeSummonObj>().Obj = summons[0]; fakeSummonObj.SetActive(true); isSkill = true; } } } break; // playerskill fakeSummon case 'B': //NO1 case 'b': isOpen = !isOpen; Bag.SetActive(isOpen); break; /* * case 'D'://NO2 * case 'd': * if(checkSummon(2)){ * float sumCD= summons [2].GetComponent<Summon> ().summonCD; * if (t3.timer (sumCD) && isPot){ * int sumCost= summons [2].GetComponent<Summon> ().summonCost; * if(cost (sumCost)){ * Instantiate (summons[2], transform.position, transform.rotation); * } * } * } * break;*/ case '3': //get 1 image name //check cd string summonName3 = summonUI.GetComponentsInChildren <RawImage> () [2].texture.name; checkEatItem(summonName3); break; case '4': //get 1 image name //check cd string summonName4 = summonUI.GetComponentsInChildren <RawImage> () [3].texture.name; checkEatItem(summonName4); break; } } }