Esempio n. 1
0
        public void OnModuleDamaged(Destructible subject)
        {
            if (OnHpAmountChanged != null)
            {
                OnHpAmountChanged();

                if (this.GetComponent <Controller>() != null)
                {
                    string name = subject.referencedObject.type.ToString().ToLower();
                    name = char.ToUpper(name[0]) + name.Substring(1);
                    if (name.IndexOf("_") >= 0)
                    {
                        name = name.Substring(0, name.IndexOf('_')) + char.ToUpper(name[name.IndexOf('_') + 1]) + name.Substring(name.IndexOf('_') + 2);
                    }
                    float hp    = 0;
                    float maxHp = 0;
                    for (int i = 0; i < modules.Count; i++)
                    {
                        if (modules[i].referencedObject.type == subject.referencedObject.type)
                        {
                            hp    += modules[i].referencedObject.hp;
                            maxHp += modules[i].referencedObject.maxHp;
                        }
                    }
                    GameObject module = GameObject.Find("GUI").transform.FindChild("Game").FindChild("Modules").FindChild(name).gameObject;
                    if (!module.activeSelf)
                    {
                        module.SetActive(true);
                    }
                    GameObject.Find("GUI").transform.FindChild("Game").FindChild("Modules").FindChild(name).GetComponent <Text>().text = (int)(hp / (maxHp / 100)) + "%";
                }
            }
        }
Esempio n. 2
0
        public void Shoot(Destructible subject, GameObject rootObject)
        {
            if (rechargeTime <= 0)
            {
                switch (weaponType)
                {
                case Weapons.MACHINE_GUN:
                {
                    GameObject p = GameObject.Instantiate(Resources.Load("Prefabs/Projectiles/" + projectileName)) as GameObject;
                    p.name = projectileName;
                    p.GetComponent <Projectile>().owner       = rootObject;
                    p.GetComponent <Projectile>().ownerWeapon = this;
                    p.transform.position = new Vector3(subject.transform.position.x, 2, subject.transform.position.z);

                    p.transform.Rotate(0, subject.transform.rotation.eulerAngles.y, subject.transform.rotation.eulerAngles.z);
                    p.transform.SetParent(GameObject.Find("Projectiles").transform);

                    System.Random r          = new System.Random();
                    float         focusRange = rootObject.GetComponent <Unit>().focusRange;
                    Vector3       direction  = (rootObject.transform.position + (rootObject.transform.forward * focusRange)) - subject.transform.position;

                    p.GetComponent <Rigidbody>().AddForce(direction.normalized * 150, ForceMode.VelocityChange);
                    rechargeTime = 60 / attackSpeed;
                    break;
                }

                case Weapons.ROCKET_LAUNCHER:
                {
                    GameObject p = GameObject.Instantiate(Resources.Load("Prefabs/Projectiles/" + projectileName)) as GameObject;
                    p.name = projectileName;
                    p.GetComponent <Projectile>().owner       = rootObject;
                    p.GetComponent <Projectile>().ownerWeapon = this;
                    p.transform.position = new Vector3(subject.transform.position.x, 2, subject.transform.position.z);

                    p.transform.Rotate(0, subject.transform.rotation.eulerAngles.y, subject.transform.rotation.eulerAngles.z);
                    p.transform.SetParent(GameObject.Find("Projectiles").transform);

                    System.Random r = new System.Random();

                    Vector3 direction = subject.transform.forward.normalized * 150;
                    direction = new Vector3(direction.x + (1 - r.Next(0, 3)), 1, direction.z + (1 - r.Next(0, 3)));

                    p.GetComponent <Rigidbody>().AddForce(direction, ForceMode.VelocityChange);
                    rechargeTime = 60 / attackSpeed;
                    break;
                }
                }
            }
        }
Esempio n. 3
0
 public void OnModuleDestroyed(Destructible sender)
 {
     if (sender.referencedObject.type == Modules.BODY)
     {
         if (this.GetComponent <Controller>() != null)
         {
             Application.LoadLevel(0);
         }
         GameObject explosion = GameObject.Instantiate(Resources.Load("Prefabs/Particles/Explosion") as GameObject);
         explosion.transform.position = this.gameObject.transform.position;
         explosion.name = "Explosion";
         GameObject.Destroy(this.gameObject);
         explosion.GetComponentInChildren <ParticleSystem>().Play();
     }
 }