I am having problems completing Tutorial Create with Code Lesson 3.3 Don't Just Stand There
I am attempting to complete the Tutorial for "Create with Code" Lesson 3.3 Don't Just Stand There. Step 6 Set up a Falling Animation I'm having problems with the code where it is referencing "other" but it appears it was never defined so I'm getting compile errors. I'm new to all of this but determined to learn.
I am also having problems with the reference to the variable jumpFoce it shows in the video example the playerRb.AddForce(Vector3.up * 10 jumpForce, ForceMode.Impulse); but this creates errors as well so I removed the "10" and the errors went away is this correct?
Here is my code for the PlayerController.cs
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { private Rigidbody playerRb; private Animator playerAnim; public float jumpForce = 10; public float gravityModifier; public bool isOnGround = true; public bool gameOver = false;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody>();
playerAnim = GetComponent<Animator>();
Physics.gravity *= gravityModifier;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
{
// The Training Video Code shows this line with a "10" before jumpForce
// whenever I try and add the "10" i get compile errors do I need the "10"
playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
isOnGround = false;
playerAnim.SetTrigger("Jump_trig");
{
}
}
}
// here is the first new reference to "other" this is where I am not sure how
// to fix this since it appears that the reference is invalid how do I fix this?
private void OnCollisionEnter(Collision collision other)
{
if (other.gameObject.CompareTag("Ground"))
{
isOnGround = true;
} else if (other.gameObject.CompareTag("Obstacle"))
{
Debug.Log("Game Over Woody");
gameOver = true;
playerAnim.SetBool("Death_b", true);
playerAnim.SetInteger("DeathType_int", 1);
}
}
}
Please Help