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. Dismiss Notice

Assets\Scripts\PlayerController.cs(32,60): error CS1001: Identifier expected

Discussion in 'Scripting' started by willyumoliver_unity, Dec 4, 2020.

  1. willyumoliver_unity

    willyumoliver_unity

    Joined:
    Nov 2, 2020
    Posts:
    4
    I dont see where the identifier error is and would love for another set of eyes to help me find it. I also would love to know how can you tell where the line with the error code is in the console error( cause from what I saw there was no error on line 32 or 60).

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour
    {
    private Rigidbody playerRb;
    public float jumpForce;
    public float gravityModifer;
    public bool isOnGround = true;
    public bool gameOver = false;
    private Animator playerAnim;

    // Start is called before the first frame update
    void Start()
    {
    playerRb = GetComponent<Rigidbody>();
    PlayerAnim = GetComponent<Animator>();
    Physics.gravity *= gravityModifer;
    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver)
    {
    playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    isOnGround = false;
    animator.SetTrigger("Jump_trig");
    }
    }
    private void OnCollisionEnter(Collision collision other)
    {
    if (other.gameObject.CompareTag("Ground"))
    {
    isOnGround = true;
    }
    else if (other.gameObject.CompareTag("Obstacle"))
    {
    gameOver = true;
    Debug.Log("Game Over");
    playerAnim.SetBool("Death_b", true);
    playerAnim.SetInteger("DeathType_int", 1);

    }
    }

    }
     
  2. zurisar

    zurisar

    Joined:
    Nov 4, 2019
    Posts:
    24
    Code (CSharp):
    1. PlayerAnim = GetComponent<Animator>();
    Maybe this?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    eses likes this.
  4. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    It is most likely due to this incorrectly defined parameter in your method:
    Code (csharp):
    1. private void OnCollisionEnter(Collision collision other)
    It would have been easier to find if you had used code tags. I expect you meant it to be:
    Code (csharp):
    1. private void OnCollisionEnter(Collision other)
     
  5. willyumoliver_unity

    willyumoliver_unity

    Joined:
    Nov 2, 2020
    Posts:
    4
    thanks you for the time you guys gave to help me, solution given about the private viod worked after I fixed another error, also thanks for informing me about the code tags I'll keep that in mind next time I need help.
     
    Kurt-Dekker likes this.