Пример #1
0
 public void SwapHull(int index)
 {
     if (CurrentHull != null)
     {
         GameObject.Destroy(CurrentHull.gameObject);
     }
     CurrentHull = GameObject.Instantiate(Hulls[index], Vector3.zero, Quaternion.identity, transform).GetComponent <Hull>();
     CurrentHull.transform.localPosition = Vector3.zero;
     CurrentHull.transform.localRotation = Quaternion.identity;
     CurrentHull.HullIndex = index;
     Oxygen.RemoveOxygen(CurrentHull.OxygenCost);
 }
Пример #2
0
    void OnCollisionEnter(Collision collision)
    {
        var oof = collision.gameObject.GetComponentInChildren <IDamageDealer>();

        if (oof != null)
        {
            var armorMultiplier = GetComponentInChildren <Hull>().ArmorMultiplier;
            var dmg             = oof.Damage * armorMultiplier;
            Oxygen.RemoveOxygen(dmg);

            CameraShaker.Shake(dmg * 4f, dmg * 10f);
        }
    }
Пример #3
0
    void Update()
    {
        // Fire
        if (Input.GetKeyDown(KeyCode.Space))
        {
            CurrentHull.Fire(true);
        }
        else if (Input.GetKeyUp(KeyCode.Space))
        {
            CurrentHull.Fire(false);
        }

        //Oxygen drop
        Oxygen.RemoveOxygen(Time.deltaTime * 0.04f);


        if (Oxygen.CurrentOxygen <= 0f)
        {
            if (DestructionPrefab != null)
            {
                GameObject.Instantiate(DestructionPrefab, transform.position, Quaternion.identity);
            }
            GameObject.Destroy(gameObject);
        }

        // Animate ship
        var horizontal     = Input.GetAxis("Horizontal");
        var vertical       = Input.GetAxis("Vertical");
        var wantedRotation = new Vector3(vertical * 8f, 0f, -horizontal * 16f);

        _rotation = new Vector3(
            Mathf.Lerp(_rotation.x, wantedRotation.x, Time.deltaTime * (Mathf.Abs(vertical) + 0.5f) * 16f),
            0f,
            Mathf.Lerp(_rotation.z, wantedRotation.z, Time.deltaTime * (Mathf.Abs(horizontal) + 0.5f) * 8f)
            );
        transform.localRotation        = Quaternion.Euler(_rotation);
        Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, _cameraOffset + (transform.position * 0.05f), Time.deltaTime * 2f);
    }