Пример #1
0
    void FixedUpdate()
    {
        selectTarget();

        //aim turret
        if (target != null)
        {
            //find the target rotation values
            Vector3 pos_diff = target.transform.position - this.transform.position;
            xTargRot = (Mathf.Atan2(Mathf.Abs(pos_diff.y), Mathf.Sqrt(pos_diff.x * pos_diff.x + pos_diff.z * pos_diff.z)) / Mathf.PI * 180);
            yTargRot = (Mathf.Atan2(pos_diff.x, pos_diff.z) / Mathf.PI * 180);
        }
        else
        {
            xTargRot = 0;
        }

        //calculate how much the turret can move based on rotation speed
        float x_rot_delta = xTargRot - xCurrRot > 180 ? xTargRot - xCurrRot - 360 : xTargRot - xCurrRot;
        float y_rot_delta = yTargRot - yCurrRot > 180 ? yTargRot - yCurrRot - 360 : yTargRot - yCurrRot;
        float speed       = target == null ? rotationSpeed / 4 : rotationSpeed;   //move slower if no target

        x_rot_delta = Mathf.Clamp(x_rot_delta, rotationSpeed * Time.deltaTime * -1, speed * Time.deltaTime);
        y_rot_delta = Mathf.Clamp(y_rot_delta, rotationSpeed * Time.deltaTime * -1, speed * Time.deltaTime);

        //update the current rotation values and rotate the transforms
        xCurrRot += x_rot_delta;
        yCurrRot += y_rot_delta;
        if (mainTransform != null)
        {
            mainTransform.localEulerAngles = new Vector3(0, yCurrRot, 0);
        }
        if (headTransform != null)
        {
            headTransform.transform.localEulerAngles = new Vector3(xCurrRot, 0, 0);
        }


        switch (turretType)
        {
        case TurretType.rifleTurret:
            this.GetComponent <Rifle>().damagePerShot = RifleDamage;
            break;

        case TurretType.rocketTurret:
            this.GetComponent <RocketLauncher>().damage = RocketDamage;
            break;

        case TurretType.cannonTurret:
            this.GetComponent <Sniper>().damagePerShot = CannonDamage;
            break;
        }


        //shoot at target
        if (equipment != null && equipment.CanActivate() && target != null)
        {
            equipment.Activate();
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        HandleHandEquip();

        if (Input.GetKeyDown("h"))
        {
            headObject.Activate(KeyCode.H);
        }
        //update Equipment
    }
Пример #3
0
 // Update is called once per frame
 void Update()
 {
     if (EquipmentHeldLeft && Input.GetMouseButtonDown(0))
     {
         EquipmentHeldLeft.Activate(KeyCode.Mouse0);
     }
     if (EquipmentHeldRight && Input.GetMouseButtonDown(1))
     {
         EquipmentHeldRight.Activate(KeyCode.Mouse1);
     }
 }
Пример #4
0
 public void OnPointerDown(PointerEventData eventData)
 {
     tooltip.Activate(recipe);
 }