I am making a game similar to flappy bird I am currently following this guy's tutorial and I'm stuck near the end I have been searching for 4hours and can't find a solution here's the code
Game Manager:
using UnityEngine;
public class GameManager : MonoBehaviour
{
private int score;
public void GameOver()
{
Debug.Log("Game Over!");
}
public void IncreaseScore()
{
score++;
}
}
player:
using UnityEngine;
public class playermove : MonoBehaviour
{
private Vector3 direction;
public float gravity = -9.8f;
public float strength = 5f;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
{
direction = Vector3.up * strength;
}
direction.y += gravity * Time.deltaTime;
transform.position += direction * Time.deltaTime;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Obstacle")
{
FindObjectOfType<GameManager>().GameOver();
} else if (other.gameObject.tag == "Score")
{
FindObjectOfType<GameManager>().IncreaseScore();
}
}
}
I'm trying to detect when the player hits a sprite with a tag and 2d collider (set as a trigger) edit: Inspector ss of trigger object