On an earlier scene my player could Jump but now he walks and nothing else…
this is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public bool isGrounded = false;
public bool Ismoving = false;
public GameObject player;
public void Update()
{
Jump();
Flip();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
Rigidbody2D rb = GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(movement.x * moveSpeed, rb.velocity.y);
}
public void Jump()
{
if (Input.GetButtonDown("Jump") && isGrounded == true) {
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
public void Flip()
{
if (Input.GetKeyDown(KeyCode.RightArrow)) {
transform.eulerAngles = new Vector3(0, 0, 0);
}else if (Input.GetKeyDown(KeyCode.LeftArrow)) {
transform.eulerAngles = new Vector3(0, 180, 0);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Platform")) {
player.transform.parent = other.gameObject.transform;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.CompareTag("Platform")) {
player.transform.parent = null;
}
}
}
and this is the isgrounded script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grounded : MonoBehaviour
{
GameObject Player;
void Start()
{
Player = gameObject.transform.parent.gameObject;
}
public void OnCollisionEnter2D(Collision2D collision2D)
{
if (collision2D.collider.tag == "Ground") {
Player.GetComponent<PlayerMovement>().isGrounded = true;
}
}
public void OnCollisionExit2D(Collision2D collision2D)
{
if (collision2D.collider.tag == "Ground") {
Player.GetComponent<PlayerMovement>().isGrounded = false;
}
}
}
another thing is it now has an error saying object refernce not set to an instance of an object
its on this line Player = gameObject.transform.parent.gameObject;