Esempio n. 1
0
    private void CreateAbilityBar()
    {
        Vector2 screenResolution = new Vector2(Screen.width, Screen.height);

        abilityBar = Instantiate(abilityBarPrefab);

        abilityBar.transform.SetParent(FindObjectOfType <Canvas>().transform);
        abilityBar.transform.position += new Vector3(screenResolution.x, screenResolution.y, 0);
        abilityBar.setAbilityCooldown(1 - _cooldownValue / Cooldown);
        //abilityBar.transform.Find("Bullet").GetComponent<Image>().color = bulletBarColor;
    }
Esempio n. 2
0
    private void Update()
    {
        if (!InGameCommon.CurrentGame.IsPaused)           // not paused
        {
            TerrainAlterationType type = TerrainAlterationType.None;
            foreach (KeyValuePair <string, TerrainAlterationType> pair in AlterationButtons)
            {
                if (Input.GetButton(pair.Key))
                {
                    type = pair.Value;
                    break;
                }
            }

            if (type != TerrainAlterationType.None)               // is holding down a button
            {
                _playerInfo.ControlState = PlayerControlState.TerrainAlteration;
                if (Physics.Raycast(
                        Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit,
                        float.PositiveInfinity, 1 << Utils.TerrainLayer
                        ))
                {
                    Vector2 hitXZ = new Vector2(hit.point.x, hit.point.z);
                    Vector2 pos   = new Vector2(transform.position.x, transform.position.z);
                    Vector2 diff  = hitXZ - pos;
                    if (type == TerrainAlterationType.Wall)
                    {
                        diff = diff.normalized;
                        pos += diff * WallAlterationDistance;
                    }
                    if (Input.GetButton("Fire") && _cooldownValue < 0.0f)                       // firing & can fire
                    {
                        float multiplier = Input.GetAxisRaw("Fire");
                        switch (type)
                        {
                        case TerrainAlterationType.Radial:
                            _gameNetwork.RPC(
                                "RPC_AlterTerrainRadial", RpcTarget.AllBufferedViaServer,
                                hitXZ, RadialAlterationRadius, multiplier * RadialAlterationDelta
                                );
                            break;

                        case TerrainAlterationType.Wall:
                            _gameNetwork.RPC(
                                "RPC_AlterTerrainWall", RpcTarget.AllBufferedViaServer,
                                pos, diff, WallAlterationLength, multiplier * WallAlterationDelta
                                );
                            break;
                        }
                        _cooldownValue += Cooldown;
                    }
                    else                         // show preview
                    {
                        Collider[] cols = null;
                        switch (type)
                        {
                        case TerrainAlterationType.Radial:
                            cols = Utils.GetPrismsInCylinder(hitXZ, RadialAlterationRadius);
                            break;

                        case TerrainAlterationType.Wall:
                            cols = Utils.GetPrismsInWall(pos, diff, WallAlterationLength);
                            break;
                        }
                        Material mat = _cooldownValue < 0.0f ? PreviewMaterial : PreviewNotReadyMaterial;
                        foreach (Collider col in cols)
                        {
                            Transform colTrans   = col.transform;
                            Vector3   previewPos = colTrans.position;
                            previewPos.y += 0.5f * colTrans.localScale.y + PreviewVerticalOffset;
                            Graphics.DrawMesh(
                                PreviewMesh, Matrix4x4.TRS(previewPos, colTrans.localRotation, colTrans.localScale), mat,
                                0, Camera.main, 0, null, false, false, false
                                );
                        }
                    }
                }
            }
            else
            {
                _playerInfo.ControlState = PlayerControlState.Shooting;
            }
        }
        // cools down no matter paused or not
        _cooldownValue = Mathf.Max(_cooldownValue, 0.0f) - Time.deltaTime;
        abilityBar.setAbilityCooldown(1 - _cooldownValue / Cooldown);
    }