I'm trying to make a simple game where you move a sphere from left/right and try to avoid falling cubes. If a cube touches the player (sphere), the player dies. I'm trying to set up boundaries using a cylinder with a collider, but every time I hit the collider boundary, the player disappears like they would if they hit a cube. Here is my player script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public float moveSpeed = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position += new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0, 0);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Cube")
{
Destroy(collision.gameObject);
Destroy(gameObject);
}
}
}