Exemplo n.º 1
0
 public void playershoot()
 {
     //点击左键并且时间已经大于间隔时间
     if (Time.time > nextFire)
     {
         PlayerInfromation p = GameObject.Find("main").GetComponent <GameController>().p;
         if (p != null && this.gameObject.name.CompareTo("DButton") == 0)
         {
             int[] inf = LevelToInformation.getLevel(p.level);
             wuliDamage = inf[0];
             mofaDamage = inf[1];
             fireRate   = inf[2];
             shoot();
         }
         else if (p != null && this.gameObject.name.CompareTo("AButton") == 0 && GameObject.Find("main").GetComponent <majorCity1>().labliang >= lanliang)
         {
             //Debug.Log("AAAAAAAAAAAAA");
             int[] inf = LevelToInformation.getPropthree(p.propthree);
             wuliDamage = inf[0];
             mofaDamage = inf[1];
             lanliang   = inf[2];
             fireRate   = inf[3];
             GameObject.Find("main").GetComponent <majorCity1>().labliang -= lanliang;
             this.gameObject.GetComponent <ButtonChange>().time            = fireRate;
             shoot();
             Destroy(Instantiate(ThisAudio, GameObject.Find("main").transform.position, Quaternion.identity), 5);
         }
     }
 }
Exemplo n.º 2
0
 public void playershoot()
 {
     enemys = GameObject.Find("main").GetComponent <GameController>().gameLevel.enemys;
     //enemys = gameObject.GetComponent<GameController>().gameLevel.enemys;
     //敌人数量不为零并且时间已经大于间隔时间
     //Debug.Log(enemys.Count);
     if (Time.time > nextFire && enemys != null && enemys.Count > 0)
     {
         if (this.gameObject.name.CompareTo("lol") == 0)
         {
             PlayerInfromation p = GameObject.Find("main").GetComponent <GameController>().p;
             if (p != null)
             {
                 int[] inf = LevelToInformation.getDefence(p.defence);
                 wuliDamage = inf[0];
                 mofaDamage = inf[1];
                 fireRate   = inf[2];
             }
         }
         //Debug.Log("tower fire");
         //更新间隔时间
         nextFire = Time.time + fireRate;
         //获得目标点
         //Vector3 target = mainTarget.localPosition;
         // Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
         Vector3 target       = new Vector3(0, 0, 0);
         float   distance     = 0;
         float   currdistance = 0;
         foreach (GameObject curr in enemys)
         {
             distance = getdistance(firepoint.position, curr.transform.position);
             if (distance > currdistance)
             {
                 currdistance = distance;
                 target       = curr.transform.position;
             }
         }
         //target = target + new Vector3(0, 0, 0);
         //firepoint.LookAt(target);
         //实例化子弹
         Vector3 temp = new Vector3(firepoint.position.x, firepoint.position.y + 0.5f, firepoint.position.z);
         //temp = new Vector3(temp.x, temp.y, temp.z);
         //temp.Set(temp.x , temp.y , temp.z );
         //clone = Instantiate(bullet, temp, firepoint.rotation, GameObject.Find("ImageTarget-Image-cam1").transform);
         Quaternion roation = Quaternion.identity;
         roation.SetFromToRotation(this.gameObject.transform.position, target);
         clone = bullet.shoot(temp, roation);
         clone.GetComponent <PlayerButtle>().wuliDamage = wuliDamage;
         clone.GetComponent <PlayerButtle>().mofaDamage = mofaDamage;
         //初始化子弹的方向速度
         clone.velocity = (target - firepoint.position) * fireSpeed;
         if (clone != null)
         {
             Destroy(clone.gameObject, fireDistance);
         }
     }
 }
Exemplo n.º 3
0
 private void initPlayer(PlayerInfromation p)
 {
     int[] inf = LevelToInformation.getCastle(p.castle);
     this.gameObject.GetComponent <majorCity1>().maxBlood    = inf[4];
     this.gameObject.GetComponent <majorCity1>().blood       = inf[4];
     this.gameObject.GetComponent <majorCity1>().maxLanliang = inf[5];
     this.gameObject.GetComponent <majorCity1>().labliang    = inf[5];
     this.gameObject.GetComponent <majorCity1>().hujia       = inf[2];
     this.gameObject.GetComponent <majorCity1>().mokang      = inf[3];
     this.gameObject.GetComponent <TowerShoot>().fireRate    = inf[6];
     this.gameObject.GetComponent <TowerShoot>().wuliDamage  = inf[0];
     this.gameObject.GetComponent <TowerShoot>().mofaDamage  = inf[1];
 }
Exemplo n.º 4
0
        public void OnClicked()
        {
            PlayerInfromation p = GameObject.Find("main").GetComponent <GameController>().p;

            if (p != null)
            {
                int[] inf = LevelToInformation.getProptwo(p.proptwo);
                damage  = inf[0];
                lanlang = inf[1];
                offset  = inf[2];
                this.gameObject.GetComponent <ButtonChange>().time = offset;
            }
            if (storm != null && Time.time > nextTime && GameObject.Find("main").GetComponent <majorCity1>().labliang >= lanlang)
            {
                nextTime = Time.time + offset;
                GameObject life = Instantiate(storm, target.transform.position + new Vector3(0, 13, 0), Quaternion.identity, cam);
                target.GetComponent <majorCity1>().labliang -= lanlang;
                Destroy(life, 8);
                stat = true;
            }
        }