Search Unity

Assets/GetGem.cs(18,13): error CS1520: Method must have a return type

Discussion in 'Editor & General Support' started by Bellmj94, Jun 25, 2022.

  1. Bellmj94

    Bellmj94

    Joined:
    Jun 13, 2022
    Posts:
    3
    Hi, so I am new to Unity, and my game was working perfectly fine until visual studios opened and suddenly all of the Scripps I had were broken. I also updated Unity itself, and it doesn't seem to have done anything, as I still keep getting thrown this error. Is there any way someone could point me in the right direction as to how to fix this I'm not sure?

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class GetGem : MonoBehaviour
    {
    public int c = 0;
    // Update is called once per frame
    private void Update()
    {
    }
    private int C => c;
    private OnTriggerEnter(UnityEngine.Collider other)
    {
    if (other is null)
    {
    throw new SystemException();
    }
    c++;
    object Debug = new();
    Destroy(obj: gameObject);
    }
    private void Destroy(object obj)
    {
    }
    public override int GetHashCode()
    {
    return base.GetHashCode();
    }
    public override bool Equals(object other)
    {
    return base.Equals(other);
    }
    public override string ToString()
    {
    return base.ToString();
    }
    }
    internal class ArgumentNullException
    {
    private global::System.String v;
    public ArgumentNullException(global::System.String v)
    {
    this.v = v;
    }
    }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,929
    Please use code tags in future.

    This line
    private OnTriggerEnter(UnityEngine.Collider other)
    should be
    private void OnTriggerEnter
    . Your IDE is believing OnTriggerEnter is the return type.
     
  3. Bellmj94

    Bellmj94

    Joined:
    Jun 13, 2022
    Posts:
    3
    I don't know whether to cheer or be super upset, because it did say void OnTriggerEnter before and told me it was wrong. omg thank you, this has been an annoying 4 days.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    I would recommend option 3: learn how to read and fix errors all by yourself. It's EASY!

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
     
  5. Bellmj94

    Bellmj94

    Joined:
    Jun 13, 2022
    Posts:
    3
    gotcha. I actually did a bit of googling before I submitted anything to the forum, and the answers I found it didn't seem to have anything to do with what I was looking for. I'm pretty sure I just didn't understand how to go about fixing the fact that it couldn't have a return type. As I said I am new to Unity and scripting in general. I'm doing this for class and didn't have any formal understanding of how scripting worked.