Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question please help my script is causing an error saying

Discussion in 'Scripting' started by Thecatking12, Sep 14, 2023.

  1. Thecatking12

    Thecatking12

    Joined:
    May 27, 2023
    Posts:
    7
    Assets\scripts\PlayerShoot.cs(7,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)

    i have looked threw the tutorial and cant find why its saying that.
    here's the code


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerShoot : MonoBehaviour
    {
    public static Action shootInput;

    private void Update()
    {
    if (Input.GetMouseButton(0))
    {
    shootInput?.Invoke();
    }
    }
    }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    You can fix your own typing mistakes. Here's how:

    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.

    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.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    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.

    Look up where the
    Action
    class is and use its namespace, either explicitly or with a using statement.
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    Would be curious to see the tutorial, as they could be using one of those IDE's that automatically include using's, while most newbie's IDE's may not be set up for it.

    @Thecatking12 if the tutorial was unclear, you need to include
    using System;
    at the top of your script with the others, as the delegate
    Action
    belongs to that namespace.