Exemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        AlienBullet bullet = other.gameObject.GetComponent <AlienBullet>();

        if (bullet &&
            bullet.GetOriginGo() != this.gameObject &&
            bullet.GetSource() != this.gameObject)
        {
            Debug.Log("Bullet incoming from other alien");
            //Add check to see if connection already exists.
            SceneUtils.FindObject <AlienTargetManager>().OnAlienTargetHit(this);
            RopeContainer ropeContainer = GameObject.Instantiate(ropeContainerPrefab, GetCenterTransform().position, Quaternion.identity);
            ropeContainer.transform.parent = this.transform;
            ropeContainer.AddEventListener(this.gameObject);

            Transform originTransform = bullet.GetOriginGo().transform;
            if (bullet.GetOriginGo().GetComponent <AlienTarget>())
            {
                originTransform =
                    bullet.GetOriginGo().GetComponent <AlienTarget>()
                    .GetCenterTransform();
            }
            ropeContainer.PrepareRope(originTransform, GetCenterTransform());
            bullet.BeforeDestroy();
            Destroy(bullet.gameObject);
            PlayInfectionSound();
            OnControlled();
        }
    }
    public void Shoot(Vector3 shootDirection)
    {
        this.GetComponent <Rigidbody>().AddForce(shootDirection * bulletSpeed, ForceMode.Impulse);
        if (ropeContainerPrefab != null)
        {
            ropeContainer = GameObject.Instantiate(ropeContainerPrefab, this.transform.position, Quaternion.identity);
            ropeContainer.AddEventListener(this.gameObject);

            Transform originTransform = GetOriginGo().transform;
            if (GetOriginGo().GetComponent <AlienTarget>())
            {
                originTransform =
                    GetOriginGo().GetComponent <AlienTarget>()
                    .GetCenterTransform();
            }
            ropeContainer.ExtendRope(originTransform, this.transform);
        }
    }