Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Following a YouTube tutorial

Discussion in 'Scripting' started by nstylesCSS, Jan 28, 2022.

  1. nstylesCSS

    nstylesCSS

    Joined:
    Jan 21, 2022
    Posts:
    5
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player : MonoBehaviour
    6. {
    7. [SerializeField]private Transform groundCheckTransform = null;
    8. private bool jumpKeyWasPressed;
    9. private float horizontalInput;
    10. private Rigidbody rigidbodyComponent;
    11.  
    12. // Start is called before the first frame update
    13. void Start()
    14. {
    15. rigidbodyComponent = GetComponent<Rigidbody>();
    16. }
    17.  
    18. // Update is called once per frame
    19. void Update()
    20. {
    21. if (Input.GetKeyDown(KeyCode.Space))
    22. {
    23. jumpKeyWasPressed = true;
    24. }
    25.  
    26. horizontalInput = Input.GetAxis("Horizontal");
    27.  
    28. }
    29. // FixedUpdate is Called once every physic update
    30. void FixedUpdate()
    31. {
    32. if (Physics.OverlapShere(groundCheckTransform.position, 0.1f).Length == 0)
    33. {
    34. return;
    35. }
    36.  
    37. if (jumpKeyWasPressed)
    38. {
    39. rigidbodyComponent.AddForce(Vector3.up *5, ForceMode.VelocityChange);
    40. jumpKeyWasPressed = false;
    41. }
    42.  
    43. rigidbodyComponent.velocity = new Vector3(horizontalInput, rigidbodyComponent.velocity.y, 0);
    44. }
    45.  
    46.  
    47. //Unity says there's a problem: Assets/Scripts/Player.cs(32,21): error CS0117: 'Physics' does not contain a definition for 'OverlapShere'
     
    Last edited: Jan 28, 2022
  2. nstylesCSS

    nstylesCSS

    Joined:
    Jan 21, 2022
    Posts:
    5
    How do I fix this? Can someone please help me? Please read the bottom. The most frustrating thing is that I followed the tutorial exactly and I can't figure out why this is happening! The youtube tutorial's link is

    at 01:37:37
     
    Last edited: Jan 28, 2022
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,991
    First step, edit your post: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Second, think about what the error says: OverlapShere, do you think you need OverlapShere? Are you sure? Open up unity's documentation, search for the Physics class and check what members does it have. Check if it has
    OverlapShere
    .

    Third, please do not put silly polls in your threads. No need to vote.
     
  4. nstylesCSS

    nstylesCSS

    Joined:
    Jan 21, 2022
    Posts:
    5
    I don't think there is an OverlapShere class, everything is there in the video and in the code. This is as specific as I can get. I just don't understand yet
     
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,991
    You have everything you need to discover and fix your mistake, you just need to follow what I said.

    Heck, you don't even have to open up the frickin' manual...
    just google the thing: https://lmgtfy.app/?q=OverlapShere