Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Помогите

Discussion in 'Scripting' started by gameunity192, Mar 12, 2022.

  1. gameunity192

    gameunity192

    Joined:
    Mar 12, 2022
    Posts:
    1
    Помогите пожалуйста
    UnassignedReferenceException: The variable cheakPosition of Player has not been assigned.
    You probably need to assign the cheakPosition variable of the Player script in the inspector.
    UnityEngine.Transform.get_position () (at <3be1a7ff939c43f181c0a10b5a0189ac>:0)
    Player.Update () (at Assets/script/Player.cs:30)
    вот код
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player : MonoBehaviour
    6. {
    7.     public float speed = 1;
    8.     public float jumpforse;
    9.  
    10.     float MoveInput;
    11.  
    12.     public bool isGrounded = false;
    13.     public float cheakRadius;
    14.     public Transform cheakPosition;
    15.     public Transform Resp;
    16.     public LayerMask Ground;
    17.  
    18.     Animator anim;
    19.     SpriteRenderer sprite;
    20.     Rigidbody2D rb;
    21.  
    22.     void Start()
    23.     {
    24.         rb = GetComponent<Rigidbody2D>();
    25.         anim = GetComponent<Animator>();
    26.         sprite = GetComponent<SpriteRenderer>();
    27.     }
    28.     void Update()
    29.     {
    30.         isGrounded = Physics2D.OverlapCircle(cheakPosition.position, cheakRadius, Ground);
    31.  
    32.         MoveInput = Input.GetAxis("Horizontal");
    33.         if(Input.GetAxis("Horizontal") == 0)
    34.         {
    35.             anim.SetBool("Anim", true);
    36.         }
    37.         else
    38.         {
    39.             anim.SetBool("Anim", false);
    40.            
    41.         }
    42.  
    43.         rb.velocity = new Vector2(MoveInput * speed, rb.velocity.y);
    44.  
    45.         if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
    46.         {
    47.             rb.AddForce(transform.up * jumpforse, ForceMode2D.Impulse);
    48.             isGrounded = false;
    49.         }
    50.         Flip();
    51.     }
    52.     void Flip()
    53.     {
    54.         if (Input.GetAxis("Horizontal") < 0)
    55.             sprite.flipX = true;
    56.         if (Input.GetAxis("Horizontal") > 0)
    57.             sprite.flipX = false;
    58.     }
    59.  
    60.     private void OnCollisionEnter2D(Collision2D other)
    61.     {
    62.         if (other.gameObject.tag == "Enemy")
    63.         {
    64.             transform.position = Resp.position;
    65.         }
    66.     }
    67. }
    68.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316