Search Unity

Create with Code tutorial not working. Error CS0246 What should the "Other" be defined as?

Discussion in 'Community Learning & Teaching' started by Ufreewoody, Jan 12, 2020.

  1. Ufreewoody

    Ufreewoody

    Joined:
    Nov 3, 2017
    Posts:
    16
    Hello, I've been having problems with my "Create with Code" tutorial not working. It appears in Lesson 3.3 Don't Just Stand There. There is a reference to the OnCollisionEnter method and it uses "other" but i believe it needs to be defined but I don't know what to set it to. Line 39 I also considered a namespace missing but what could that be?

    error CS0246: The type or namespace name `_other_______' Could not be found.
    Are you missing a using directive of assembly reference?

    I am a Newbie but I wanna do things right so here is the code with the Code Tags
    Please Help

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class PlayerController : MonoBehaviour
    7. {
    8.     private Rigidbody playerRb;
    9.     private Animator playerAnim;
    10.     public float jumpForce = 10;
    11.     public float gravityModifier;
    12.     public bool isOnGround = true;
    13.     public bool gameOver = false;
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         playerRb = GetComponent<Rigidbody>();
    19.         playerAnim = GetComponent<Animator>();
    20.         Physics.gravity *= gravityModifier;
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.         if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
    27.         {
    28.             playerRb.AddForce(Vector3.up * 10 * jumpForce, ForceMode.Impulse);
    29.             isOnGround = false;
    30.             playerAnim.SetTrigger("Jump_trig");
    31.             {
    32.  
    33.             }
    34.         }
    35.     }
    36.     // here is the first new reference to "other" this is where I am not sure how
    37.     // to fix this since it appears that the reference is invalid how do I fix this?
    38.         private void OnCollisionEnter(Collision collision other)
    39.     {
    40.             if (other.gameObject.CompareTag("Ground"))
    41.         {
    42.             isOnGround = true;
    43.         }   else if (other.gameObject.CompareTag("Obstacle"))
    44.         {
    45.             Debug.Log("Game Over Woody");
    46.             gameOver = true;
    47.             playerAnim.SetBool("Death_b", true);
    48.             playerAnim.SetInteger("DeathType_int", 1);
    49.         }
    50.     }
    51. }
    52.