// Update is called once per frame void Update() { if (!boos) { m_timer -= Time.deltaTime; } if (m_timer <= 0.0) { // 生成敌人 Transform obj = (Transform)Instantiate(m_enemy, m_transform.position, Quaternion.identity); // 获取敌人的脚本 BadAss badAss = obj.GetComponent <BadAss>(); // 初始化敌人 badAss.Init(this); m_timer = 20.0f; boos = true; } }
void shoot() { //if (SpecialMagOn) //{ // //SpecialAmmoShooted = SpecialMag.Pop(); //} m_shootTimer = 0.1f; m_special_shootTimer = 0.9f; // 减少弹药,更新弹药UI // RaycastHit用来保存射线的探测结果 RaycastHit info; RaycastHit info_ass; // 从muzzlepoint的位置,向摄像机面向的正方向射出一根射线 // 射线只能与m_layer所指定的层碰撞 bool hit_ass = Physics.Raycast(m_muzzlepoint.position, m_camTransform.TransformDirection(Vector3.forward), out info_ass, 100, m_layer_ass); bool hit = Physics.Raycast(m_muzzlepoint.position, m_camTransform.TransformDirection(Vector3.forward), out info, 100, m_layer); //Debug.Log("info:"+info.transform.tag); if (hit) { //Debug.Log("info_ass:"+info_ass.transform.tag); // 如果射中了Tag为enemy的游戏体 if (SpecialMagOn) { if (info_ass.collider != null) { //Debug.Log(info_ass.transform.tag); if (info_ass.transform.tag.CompareTo("Left") == 0) { BadAss badAss = info.transform.GetComponent <BadAss>(); badAss.m_ani.SetTrigger("left"); } else if (info_ass.transform.tag.CompareTo("Right") == 0) { BadAss badAss = info.transform.GetComponent <BadAss>(); badAss.m_ani.SetTrigger("right"); } else if (info_ass.transform.tag.CompareTo("head") == 0) { BadAss badAss = info.transform.GetComponent <BadAss>(); badAss.m_ani.SetTrigger("head"); } else if (info_ass.transform.tag.CompareTo("body") == 0) { BadAss badAss = info.transform.GetComponent <BadAss>(); badAss.m_ani.SetTrigger("body"); } } } if (info.transform.tag.CompareTo("enemy") == 0) { Enemy enemy = info.transform.GetComponent <Enemy>(); BadAss badAss = info.transform.GetComponent <BadAss>(); if (!SpecialMagOn) { if (enemy) { enemy.OnDamage(1 + cntAtk); } else { badAss.OnDamage(1 + cntAtk); } } else { if (SpecialMag.Count != 0) { switch (SpecialMag.Pop()) { case SpecialAmmo.ShcokedAmmo: if (enemy) { enemy.Shocked = true; enemy.OnDamage(3 + cntAtk); } else { badAss.m_ani.SetBool("shocked", true); badAss.Shocked = true; badAss.OnDamage(3 + cntAtk); } break; case SpecialAmmo.OnFireAmmo: if (enemy) { enemy.OnFire = true; enemy.OnDamage(1 + cntAtk); } else { badAss.OnFire = true; badAss.OnDamage(1 + cntAtk); } break; case SpecialAmmo.ElectricAmmo: //连锁功能,可通过rigibody组件来实现 if (enemy) { enemy.OnDamage(10 + cntAtk); } else { badAss.OnDamage(10 + cntAtk); } break; case SpecialAmmo.DamAmmo: if (enemy) { enemy.OnDamage(100 + cntAtk); } else { badAss.OnDamage(100 + cntAtk); } break; case SpecialAmmo.NormalAmmo: if (enemy) { enemy.OnDamage(1 + cntAtk); } else { badAss.OnDamage(1 + cntAtk); } break; } } } GameManager.Instance.SetAmmo(1); } else { if (SpecialMagOn) { SpecialMag.Pop(); } GameManager.Instance.SetAmmo(1); } // 在射中的地方释放一个粒子效果 Instantiate(m_fx, info.point, info.transform.rotation); } }