Пример #1
0
 private void Awake()
 {
     p_rigidbody = GetComponent <Rigidbody2D>();
     if (groundDetector == null)
     {
         groundDetector = GetComponent <GroundDetector>();
     }
 }
Пример #2
0
        private void Start()
        {
            _rigidBody      = GetComponent <Rigidbody>();
            _capsule        = GetComponent <CapsuleCollider>();
            _audioSource    = GetComponent <AudioSource>();
            _groundDetector = GetComponent <GroundDetector>();
            MouseLook.Init(transform, Camera.transform);

            MoveAction.Enable();
            MoveAction.started   += HandleMovement;
            MoveAction.performed += HandleMovement;
            MoveAction.canceled  += HandleStopMovement;

            JumpAction.Enable();
            JumpAction.started += HandleJump;
        }
Пример #3
0
        private void Awake()
        {
            state     = new PlayerState();
            rigidbody = GetComponent <Rigidbody>();
            collider  = GetComponent <Collider>();
            material  = GetComponent <Renderer>().material;

            if (collider == null)
            {
                Debug.LogError("Player collider is null!");
            }

            // register player to controller
            GetComponent <Controller>().player = this;

            // register to ground detector
            GroundDetector gd = GetComponent <GroundDetector>();

            if (gd != null)
            {
                gd.RegisterOnGroundHit(HitGround);
                gd.RegisterOnGroundLeave(LeaveGround);
            }
            else
            {
                Debug.LogError("Ground detector not found!");
            }

            // check player Mode
            if (gd.GroundState())
            {
                state.SetMode(Mode.Ground);
            }
            else
            {
                state.SetMode(Mode.Air);
            }

            layerMask = LayerMask.GetMask(new string[] { "Obstacle", "Default" });

            // register to face collision detection
            FaceCollisionDetector fcd = transform.Find("FaceCollisionDetector")
                                        .GetComponent <FaceCollisionDetector>();

            fcd.Register(FaceHit);
        }