@nonenonenoenoneone

Привет, почему у меня выкидывает ошибку?

в чем ошибка?
// Copyright 2021, Infima Games. All Rights Reserved.

using System.Linq;
using UnityEngine;
using Photon.Pun;

namespace InfimaGames.LowPolyShooterPack
{
    [RequireComponent(typeof(Rigidbody), typeof(CapsuleCollider))]
    public class Movement : MovementBehaviour
    {
        PhotonView view;

        private void Awake()
        {
            view = GetComponent<PhotonView>();

            if(!view.IsMine)
            {
                Camera.SetActive(false);
                Movementcontroller.enabled = false;
            }
        }

        public GameObject Camera;

        public Movement Movementcontroller;

        #region FIELDS SERIALIZED

        [Header("Audio Clips")]
        
        [Tooltip("The audio clip that is played while walking.")]
        [SerializeField]
        private AudioClip audioClipWalking;

        [Tooltip("The audio clip that is played while running.")]
        [SerializeField]
        private AudioClip audioClipRunning;

        [Header("Speeds")]

        [SerializeField]
        private float speedWalking = 5.0f;

        [Tooltip("How fast the player moves while running."), SerializeField]
        private float speedRunning = 9.0f;

        #endregion

        #region PROPERTIES

        //Velocity.
        private Vector3 Velocity
        {
            //Getter.
            get => rigidBody.velocity;
            //Setter.
            set => rigidBody.velocity = value;
        }

        #endregion

        #region FIELDS

        /// <summary>
        
        /// </summary>
        private Rigidbody rigidBody;
        /// <summary>
        
        /// </summary>
        private CapsuleCollider capsule;
        /// <summary>
        
        /// </summary>
        private AudioSource audioSource;
        
        /// <summary>
        
        /// </summary>
        private bool grounded;

        /// <summary>
        
        /// </summary>
        private CharacterBehaviour playerCharacter;
        /// <summary>
        
        /// </summary>
        private WeaponBehaviour equippedWeapon;
        
        /// <summary>
        
        /// </summary>
        private readonly RaycastHit[] groundHits = new RaycastHit[8];

        #endregion

        #region UNITY FUNCTIONS

        /// <summary>
        /// Awake.
        /// </summary>
        protected override void Awake()
        { 
            playerCharacter = ServiceLocator.Current.Get<IGameModeService>().GetPlayerCharacter();
        }

       
        protected override  void Start()
        {        
            rigidBody = GetComponent<Rigidbody>();
            rigidBody.constraints = RigidbodyConstraints.FreezeRotation;
            
            capsule = GetComponent<CapsuleCollider>();
          
            audioSource = GetComponent<AudioSource>();
            audioSource.clip = audioClipWalking;
            audioSource.loop = true;
        }

       
        private void OnCollisionStay()
        {          
            Bounds bounds = capsule.bounds;
            
            Vector3 extents = bounds.extents;
            
            float radius = extents.x - 0.01f;            
            
            Physics.SphereCastNonAlloc(bounds.center, radius, Vector3.down,
                groundHits, extents.y - radius * 0.5f, ~0, QueryTriggerInteraction.Ignore);
                        
            if (!groundHits.Any(hit => hit.collider != null && hit.collider != capsule)) 
                return;
                    
            for (var i = 0; i < groundHits.Length; i++)
                groundHits[i] = new RaycastHit();
				
            grounded = true;
        }
			
        protected override void FixedUpdate()
        {
            MoveCharacter();   
            
            grounded = false;
        }

       
        protected override  void Update()
        {
            equippedWeapon = playerCharacter.GetInventory().GetEquipped();
            
            PlayFootstepSounds();
        }

        #endregion

        #region METHODS

        private void MoveCharacter()
        {
            #region Calculate Movement Velocity

            //Get Movement Input!
            Vector2 frameInput = playerCharacter.GetInputMovement();
            //Calculate local-space direction by using the player's input.
            var movement = new Vector3(frameInput.x, 0.0f, frameInput.y);
            
            //Running speed calculation.
            if(playerCharacter.IsRunning())
                movement *= speedRunning;
            else
            {
                //Multiply by the normal walking speed.
                movement *= speedWalking;
            }

            //World space velocity calculation. This allows us to add it to the rigidbody's velocity properly.
            movement = transform.TransformDirection(movement);

            #endregion
            
            //Update Velocity.
            Velocity = new Vector3(movement.x, 0.0f, movement.z);
        }

        /// <summary>
        /// Plays Footstep Sounds. This code is slightly old, so may not be great, but it functions alright-y!
        /// </summary>
        private void PlayFootstepSounds()
        {
            //Check if we're moving on the ground. We don't need footsteps in the air.
            if (grounded && rigidBody.velocity.sqrMagnitude > 0.1f)
            {
                //Select the correct audio clip to play.
                audioSource.clip = playerCharacter.IsRunning() ? audioClipRunning : audioClipWalking;
                //Play it!
                if (!audioSource.isPlaying)
                    audioSource.Play();
            }
            //Pause it if we're doing something like flying, or not moving!
            else if (audioSource.isPlaying)
                audioSource.Pause();
        }

        #endregion
    }
}

сама ошибка выглядит так - main floder\Code\Character\Movement.cs(106,33): error CS0111: Type 'Movement' already defines a member called 'Awake' with the same parameter types
  • Вопрос задан
  • 128 просмотров
Пригласить эксперта
Ответы на вопрос 2
GavriKos
@GavriKos Куратор тега Разработка игр
Ну два Awake, нельзя так. Что делать - хз, полотно ваше, сами и решайте
Ответ написан
@MasterGod
Ошибка возникает из-за того, что в классе Movement уже определен метод Awake с такими же параметрами. В C# нельзя определить два метода с одинаковыми именами и одинаковыми параметрами.

Чтобы исправить ошибку, можно удалить метод Awake в классе Movement или изменить его имя или параметры, чтобы они отличались от другого метода Awake в классе.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы