C
C#6mo ago
me_camel

can somebody help me,

can somebody help me, i keep getting the error , "PlayerInteract.cs(21,10):error CS0111: Type 'PlayerInteract' already defines a member called 'Update' with the same parameter types" my code is,
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInteract : MonoBehaviour
{
private Camera cam;
[SerializeField]
private float distance = 3f;
[SerializeField]
private LayerMask mask;
private PlayerUI playerUI;
// Start is called before the first frame update
void Start()
{
cam = GetComponent<PlayerLook>().cam;
playerUI = GetComponent<PlayerUI>();
}

// Update is called once per frame
void Update()
{
playerUI.UpdateText(string.Empty);
// Create a ray at the center of the camera, shooting outwards
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
Debug.DrawRay(ray.origin, ray.direction * distance);
RaycastHit hitInfo; // Variable to store the collision information
if (Physics.Raycast(ray, out hitInfo, distance, mask))
{
if (hitInfo.collider.GetComponent<Interactable>() != null)
{
playerUI.UpdateText(hitInfo.collider.GetComponent<Interactable>().promptMessage);
}
}
}
}
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInteract : MonoBehaviour
{
private Camera cam;
[SerializeField]
private float distance = 3f;
[SerializeField]
private LayerMask mask;
private PlayerUI playerUI;
// Start is called before the first frame update
void Start()
{
cam = GetComponent<PlayerLook>().cam;
playerUI = GetComponent<PlayerUI>();
}

// Update is called once per frame
void Update()
{
playerUI.UpdateText(string.Empty);
// Create a ray at the center of the camera, shooting outwards
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
Debug.DrawRay(ray.origin, ray.direction * distance);
RaycastHit hitInfo; // Variable to store the collision information
if (Physics.Raycast(ray, out hitInfo, distance, mask))
{
if (hitInfo.collider.GetComponent<Interactable>() != null)
{
playerUI.UpdateText(hitInfo.collider.GetComponent<Interactable>().promptMessage);
}
}
}
}
and i can ss my code
13 Replies
becquerel
becquerel6mo ago
it means you have the method Update() twice
Angius
Angius6mo ago
Does MonoBehaviour have an Update method? If so, you're meant to override it
me_camel
me_camelOP6mo ago
how how do i override
Angius
Angius6mo ago
Huh, or maybe not, actually You sure you have only one Update method there?
Hannsen
Hannsen6mo ago
I had a look at the unity docs and the MonoBehavior Class. - Seems like nothing is wrong with your code because there is no virtual Update in the base Class.
Hannsen
Hannsen6mo ago
I found this on reddit:
No description
me_camel
me_camelOP6mo ago
yes want me to ss my code?
Angius
Angius6mo ago
No need
me_camel
me_camelOP6mo ago
ive been stuck on this problem for 2 days now its been a complete stop to my game development
Angius
Angius6mo ago
Check what Hannsen posted Maybe you also have some leftover duplicate classes or something
me_camel
me_camelOP6mo ago
ok how do i go in the unity files
Hannsen
Hannsen6mo ago
Open the windows file explorer, go to your unity project, and look for duplicate classes there
me_camel
me_camelOP6mo ago
ok thank you it worked ur a goat fr
Want results from more Discord servers?
Add your server