public void EnableWeapon(bool enable)
    {
        if ((enable && !weaponDisabled) || (!enable && weaponDisabled))
        {
            return;
        }

        PlayerGO  playerGO = GetComponent <PlayerGO>();
        Animation anim     = playerGO.weaponHolderFP.Find(activeWeapon.weapon.name).GetComponent <Animation>();

        /* if (!enable) {
         *   anim["draw"].speed = -1;
         *   anim["draw"].time = anim["draw"].length;
         * }
         * else {
         *   anim["draw"].speed = 1;
         * }*/

        if (!enable)
        {
            FPSController.instance.weaponAnimations.wrapMode = WrapMode.Once;
            FPSController.instance.weaponAnimations.Play("WeaponDown");
        }
        else
        {
            FPSController.instance.weaponAnimations.Play("WeaponUp");
            FPSController.instance.weaponAnimations.wrapMode = WrapMode.Loop;
        }

        weaponDisabled = !enable;
    }
 /// <summary>
 /// Se obtienen todas las instancias del juego
 /// </summary>
 private void GetInstances()
 {
     memoramaManager = MemoramaManager.Instance;
     fightScript     = FightScript.Instance;
     renewBoard      = RenewBoard.Instance;
     player          = PlayerGO.Instance;
     enemy           = EnemyGO.Instance;
     SetHealthAndDamage();
     renewBoard.GetBoardChildren();
     fightButton.onClick.AddListener(fightScript.ApplyDammage);
     renewButton.onClick.AddListener(renewBoard.CheckIfBoardCanBeRenewed);
 }
Exemple #3
0
 // Start is called before the first frame update
 private void Awake()
 {
     if (instance == null)
     {
         playerInstance = Player.Instance;
         instance       = this;
     }
     else
     {
         Destroy(this);
     }
 }
    void playShootSoundRPC(PhotonMessageInfo pmi)
    {
        Player   player   = Player.FindPlayer(pmi.sender);
        PlayerGO playerGO = player.gameObject.GetComponent <PlayerGO>();

        playerGO.weaponShootSoundAS.Stop();

        /* Transform al = CamerasManager.cameras[CameraEnum.sceneCamera].transform;
         *
         * if (Player.myPlayer.gameObject != null)
         *   al = Player.myPlayer.gameObject.transform;*/

        playerGO.weaponShootSoundAS.PlayOneShot(weaponsShootSounds[playerGO.GetComponent <WeaponsManager>().activeWeapon.weapon.Enum]);
    }
    private void Awake()
    {
        if (instance != null)
        {
            Debug.LogWarning("More than one instance of PlayerManager found !");
            return;
        }
        instance = this;

        PlayerController = PlayerGO.GetComponent <PlayerController>();
        PlayerCombat     = PlayerGO.GetComponent <CharacterCombat>();
        //PlayerStats = PlayerGO.GetComponent<PlayerStats>();
        PlayerAnimator = PlayerGO.GetComponent <PlayerAnimator>();
        PlayerLevel    = PlayerGO.GetComponent <PlayerLevel>();
        PlayerFocus    = PlayerGO.GetComponent <PlayerFocus>();
        Player         = PlayerGO.GetComponent <Player>();
    }
    void Reload()
    {
        if (aiming)
        {
            forceReload = true;
            doAim(false);
            return;
        }

        forceReload         = false;
        activeWeapon.status = WeaponStatus.reloading;
        reloadCooldown      = activeWeapon.weapon.reloadTime;
        PlayerGO playerGO = GetComponent <PlayerGO>();

        playerGO.weaponsReloadSoundsAS.PlayOneShot(SoundsManager.weaponsReloadSounds[activeWeapon.weapon.Enum]);
        playerGO.weaponHolderFP.Find(activeWeapon.weapon.name).GetComponent <Animation>().Play("reload");
        GetComponent <PhotonView>().RPC("setReloadAnim", PhotonTargets.All);
    }
    public void AttackTarget(Collider2D attackTarget, Animator animator)
    {
        pathfindingGridSetupScript = GameObject.Find("PathfindingGridSetup").GetComponent <PathfindingGridSetup>();
        cellSize = pathfindingGridSetupScript.pathfindingGrid.GetCellSize();

        daAnimator = animator;
        Entity        entity        = convertedEntityHolder.GetEntity();
        EntityManager entityManager = convertedEntityHolder.GetEntityManager();


        PathFollowComp pathFollowComp = entityManager.GetComponentData <PathFollowComp>(entity);
        DynamicBuffer <PathPositionBuffer> pathPositionBuffer = entityManager.GetBuffer <PathPositionBuffer>(entity);

        if (DidColliderChange(attackTarget))
        {
            lastAttackTarget            = attackTarget;
            attackTargetCurrentPosition = attackTarget.transform.position;
            playerGOScript = attackTarget.GetComponent <PlayerGO>();
            // Add pathfinding params
            pathfindingGridSetupScript.pathfindingGrid.GetXY(attackTargetCurrentPosition + new Vector3(1, 1) * cellSize * 0.5f, out int endX, out int endY);
            ValidateGridPosition(ref endX, ref endY);
            pathfindingGridSetupScript.pathfindingGrid.GetXY(transform.position + new Vector3(1, 1) * cellSize * 0.5f, out int startX, out int startY);
            ValidateGridPosition(ref startX, ref startY);

            entityManager.AddComponentData(entity, new PathfindingParams
            {
                startPosition = new int2(startX, startY),
                endPosition   = new int2(endX, endY)
            });
            return;
        }

        if (currentAttackCooldown > 0)
        {
            currentAttackCooldown -= Time.deltaTime;
        }
        if (attackTarget.gameObject.activeSelf)
        {
            //attackTargetCurrentPosition = attackTarget.transform.position;

            // if target hasn't moved 0.25f length away from last pathfinding target position then run
            //      attack code, else, set new pathfinding params
            if (Vector3.Distance(attackTarget.transform.position, attackTargetCurrentPosition) < 1f)
            {
                // if player is within attack range then attack, else move towards target
                // later on need to factor in size of target in this check
                if (Vector3.Distance(transform.position, attackTarget.transform.position) < hostileAttackRange)
                {
                    if (currentAttackCooldown <= 0)
                    {
                        //animator.SetBool("isWalking", false);
                        currentAttackCooldown = hostileAttackCooldown;
                        // attack
                        StartCoroutine(HostileAttack());
                    }
                }
                else // move towards target
                {
                    if (pathFollowComp.pathIndex >= 0)
                    {
                        int2 pathPosition = pathPositionBuffer[pathFollowComp.pathIndex].position;

                        float3 targetPosition = new float3(pathPosition.x, pathPosition.y, 0);
                        float3 moveDir        = math.normalizesafe(targetPosition - (float3)transform.position);

                        animator.SetFloat("moveX", moveDir.x);
                        animator.SetFloat("moveY", moveDir.y);

                        transform.position += (Vector3)(moveDir * hostileSpeed * Time.deltaTime);

                        if (math.distance(transform.position, targetPosition) < 0.1f)
                        {
                            // next waypoint
                            pathFollowComp.pathIndex--;
                            entityManager.SetComponentData(entity, pathFollowComp);
                        }
                    }
                    else
                    {
                        Vector3 moveDir = (attackTarget.transform.position - transform.position).normalized;
                        transform.position += moveDir * hostileSpeed * Time.deltaTime;
                    }
                }
            }
            else
            {
                attackTargetCurrentPosition = attackTarget.transform.position;
                // Add pathfinding params
                pathfindingGridSetupScript.pathfindingGrid.GetXY(attackTargetCurrentPosition + new Vector3(1, 1) * cellSize * 0.5f, out int endX, out int endY);
                ValidateGridPosition(ref endX, ref endY);
                pathfindingGridSetupScript.pathfindingGrid.GetXY(transform.position + new Vector3(1, 1) * cellSize * 0.5f, out int startX, out int startY);
                ValidateGridPosition(ref startX, ref startY);

                entityManager.AddComponentData(entity, new PathfindingParams
                {
                    startPosition = new int2(startX, startY),
                    endPosition   = new int2(endX, endY)
                });
            }
        }
        else // if target was destroyed
        {
            // for now do nothing, later find new target
        }
    }