I’m fairly new to unity, so I’d like to apologize if this question sounds stupid. I’m trying to make pac-man in 3D as my first unity project and things have been going really smooth. (I’m almost done, in fact!) All I need to add is a way for the player (pac man) to detect if a ghost is touching it. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PacManMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.UpArrow))
{
// Moves an object forward, relative to its own rotation.
transform.position += transform.forward * 4 * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow))
{
// Moves an object down, relative to its own rotation.
transform.position += -transform.forward * 4 * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow))
{
// Moves an object right, relative to its own rotation.
transform.position += transform.right * 4 * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
// Moves an object left, relative to its own rotation.
transform.position += -transform.right * 4 * Time.deltaTime;
}
}
}
Can someone please help me without changing the code I’ve already written?
Can you show me how you would write "OnCollisionEnter" under the update() function? I've seen alot of people use this function which is why I'd be willing to try your idea first (also your idea is much more easier)
– Doorplate