Exemplo n.º 1
0
    void Start()
    {
        // fetch components on the same gameObject
        m_Controller = GetComponent <CharacterController>();
        DebugUtility.HandleErrorIfNullGetComponent <CharacterController, IS_PlayerCharacterController>(m_Controller, this, gameObject);

        m_InputHandler = GetComponent <PlayerInputHandler>();
        DebugUtility.HandleErrorIfNullGetComponent <PlayerInputHandler, IS_PlayerCharacterController>(m_InputHandler, this, gameObject);

        m_WeaponsManager = GetComponent <IS_PlayerWeaponsManager>();
        DebugUtility.HandleErrorIfNullGetComponent <IS_PlayerWeaponsManager, IS_PlayerCharacterController>(m_WeaponsManager, this, gameObject);

        m_Health = GetComponent <Health>();
        DebugUtility.HandleErrorIfNullGetComponent <Health, IS_PlayerCharacterController>(m_Health, this, gameObject);

        m_Actor = GetComponent <Actor>();
        DebugUtility.HandleErrorIfNullGetComponent <Actor, IS_PlayerCharacterController>(m_Actor, this, gameObject);

        m_Controller.enableOverlapRecovery = true;

        m_Health.onDie += OnDie;

        // force the crouch state to false when starting
        SetCrouchingState(false, true);
        UpdateCharacterHeight(true);
    }
Exemplo n.º 2
0
    private void Awake()
    {
        controls        = new RoseInputSettings();
        gamepadControls = new RoseInputSettings1();
        myPlayerInput   = GetComponent <PlayerInput>();

        WeaponsManager = GetComponent <IS_PlayerWeaponsManager>();
        MenuManager    = FindObjectOfType <InGameMenuManager>();
    }
Exemplo n.º 3
0
    public void Initialize(WeaponController weapon, int weaponIndex)
    {
        m_Weapon           = weapon;
        weaponCounterIndex = weaponIndex;
        weaponImage.sprite = weapon.weaponIcon;

        m_IS_PlayerWeaponsManager = FindObjectOfType <IS_PlayerWeaponsManager>();
        DebugUtility.HandleErrorIfNullFindObject <IS_PlayerWeaponsManager, AmmoCounter>(m_IS_PlayerWeaponsManager, this);

        weaponIndexText.text = (weaponCounterIndex + 1).ToString();

        FillBarColorChange.Initialize(1f, m_Weapon.GetAmmoNeededToShoot());
    }
Exemplo n.º 4
0
    void OnPicked(IS_PlayerCharacterController byPlayer)
    {
        IS_PlayerWeaponsManager IS_PlayerWeaponsManager = byPlayer.GetComponent <IS_PlayerWeaponsManager>();

        if (IS_PlayerWeaponsManager)
        {
            if (IS_PlayerWeaponsManager.AddWeapon(weaponPrefab))
            {
                // Handle auto-switching to weapon if no weapons currently
                if (IS_PlayerWeaponsManager.GetActiveWeapon() == null)
                {
                    IS_PlayerWeaponsManager.SwitchWeapon(true);
                }

                m_Pickup.PlayPickupFeedback();

                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 5
0
    void OnShoot()
    {
        m_ShootTime         = Time.time;
        m_LastRootPosition  = root.position;
        m_Velocity          = transform.forward * speed;
        m_IgnoredColliders  = new List <Collider>();
        transform.position += m_ProjectileBase.inheritedMuzzleVelocity * Time.deltaTime;

        // Ignore colliders of owner
        Collider[] ownerColliders = m_ProjectileBase.owner.GetComponentsInChildren <Collider>();
        m_IgnoredColliders.AddRange(ownerColliders);

        // Handle case of player shooting (make projectiles not go through walls, and remember center-of-screen trajectory)
        IS_PlayerWeaponsManager IS_PlayerWeaponsManager = m_ProjectileBase.owner.GetComponent <IS_PlayerWeaponsManager>();

        if (IS_PlayerWeaponsManager)
        {
            m_HasTrajectoryOverride = true;

            Vector3 cameraToMuzzle = (m_ProjectileBase.initialPosition - IS_PlayerWeaponsManager.weaponCamera.transform.position);

            m_TrajectoryCorrectionVector = Vector3.ProjectOnPlane(-cameraToMuzzle, IS_PlayerWeaponsManager.weaponCamera.transform.forward);
            if (trajectoryCorrectionDistance == 0)
            {
                transform.position += m_TrajectoryCorrectionVector;
                m_ConsumedTrajectoryCorrectionVector = m_TrajectoryCorrectionVector;
            }
            else if (trajectoryCorrectionDistance < 0)
            {
                m_HasTrajectoryOverride = false;
            }

            if (Physics.Raycast(IS_PlayerWeaponsManager.weaponCamera.transform.position, cameraToMuzzle.normalized, out RaycastHit hit, cameraToMuzzle.magnitude, hittableLayers, k_TriggerInteraction))
            {
                if (IsHitValid(hit))
                {
                    OnHit(hit.point, hit.normal, hit.collider);
                }
            }
        }
    }
Exemplo n.º 6
0
    void Start()
    {
        if (desiredPlayer != null)
        {
            m_IS_PlayerWeaponsManager = desiredPlayer.GetComponent <IS_PlayerWeaponsManager>();
        }
        // m_IS_PlayerWeaponsManager = FindObjectOfType<IS_PlayerWeaponsManager>();
        DebugUtility.HandleErrorIfNullFindObject <IS_PlayerWeaponsManager, WeaponHUDManager>(m_IS_PlayerWeaponsManager, this);

        WeaponController activeWeapon = m_IS_PlayerWeaponsManager.GetActiveWeapon();

        if (activeWeapon)
        {
            AddWeapon(activeWeapon, m_IS_PlayerWeaponsManager.activeWeaponIndex);
            ChangeWeapon(activeWeapon);
        }

        m_IS_PlayerWeaponsManager.onAddedWeapon      += AddWeapon;
        m_IS_PlayerWeaponsManager.onRemovedWeapon    += RemoveWeapon;
        m_IS_PlayerWeaponsManager.onSwitchedToWeapon += ChangeWeapon;
    }