using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float jumpPower = 100f;
Rigidbody2D myRigidbody;
bool isRoad = false;
bool isGameOver = false;
public float xPos = -17.4f;
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (isGameOver) return;
if (Input.GetKey(KeyCode.Space) && isRoad )
{
myRigidbody.AddForce(Vector3.up *myRigidbody.gravityScale*myRigidbody.mass* jumpPower * Time.deltaTime );
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if(other.collider.tag == "Road")
{
isRoad = true;
}
if(other.collider.tag == "Obstacles")
{
GameOver();
}
}
private void OnCollisionExit2D(Collision2D other)
{
if(other.collider.tag == "Road")
{
isRoad = false;
}
}
private void OnCollisionStay2D(Collision2D other)
{
if(other.collider.tag == "Road")
{
isRoad = true;
}
}
public void GameOver()
{
myRigidbody.gravityScale = 0f;
isGameOver = true;
FindObjectOfType<ChallengeScroller>().GameOver();
FindObjectOfType<Scroll>().xVel =0f;
FindObjectOfType<ScrollClouds>().xVel =0f;
}
}
- This is the normal text
please tell me what should I add extra codes are am I doing any errors, although player and obstacles are not getting collide with each other, instead obstacles are pushing the player backside. here I have used to call the Gameover function
`if(other.collider.tag == "Obstacles") { GameOver();
}`