Search Unity

Error CS0246

Discussion in 'Scripting' started by dax005, Sep 21, 2019.

  1. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    Hello im new in Unity and i cant find solution for this error, i tried to fix it but nothing works, do anyone know how to fix it. This is what the error looks like:

    Assets\SampleScenes\Scripts\ParticleSceneControls.cs(42,17): error CS0246: The type or namespace name 'Particle' could not be found (are you missing a using directive or an assembly reference?)



    Thats the code that im using:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.EventSystems;
    5. using UnityEngine.UI;
    6. using UnityStandardAssets;
    7.  
    8.  
    9.  
    10. namespace UnityStandardAssets.SceneUtils
    11. {
    12.     public class ParticleSceneControls : MonoBehaviour
    13.     {
    14.  
    15.         public enum Mode
    16.         {
    17.             Activate,
    18.             Instantiate,
    19.             Trail
    20.         }
    21.  
    22.         public enum AlignMode
    23.         {
    24.             Normal,
    25.             Up
    26.         }
    27.  
    28.  
    29.         public DemoParticleSystemList demoParticles;
    30.         public float spawnOffset = 0.5f;
    31.         public float multiply = 1;
    32.         public bool clearOnChange = false;
    33.         public Text titleText;
    34.         public Transform sceneCamera;
    35.         public Text instructionText;
    36.         public Button previousButton;
    37.         public Button nextButton;
    38.         public GraphicRaycaster graphicRaycaster;
    39.         public EventSystem eventSystem;
    40.  
    41.  
    42.         private Particle.SystemMultiplier m_ParticleMultiplier;
    43.         private List<Transform> m_CurrentParticleList = new List<Transform>();
    44.         private Transform m_Instance;
    45.         private static int s_SelectedIndex = 0;
    46.         private Vector3 m_CamOffsetVelocity = Vector3.zero;
    47.         private Vector3 m_LastPos;
    48.         private static DemoParticleSystem s_Selected;
    49.  
    50.  
    51.         private void Awake()
    52.         {
    53.             Select(s_SelectedIndex);
    54.  
    55.             previousButton.onClick.AddListener(Previous);
    56.             nextButton.onClick.AddListener(Next);
    57.         }
    58.  
    59.  
    60.         private void OnDisable()
    61.         {
    62.             previousButton.onClick.RemoveListener (Previous);
    63.             nextButton.onClick.RemoveListener (Next);
    64.         }
    65.  
    66.  
    67.         private void Previous()
    68.         {
    69.             s_SelectedIndex--;
    70.             if (s_SelectedIndex == -1)
    71.             {
    72.                 s_SelectedIndex = demoParticles.items.Length - 1;
    73.             }
    74.             Select(s_SelectedIndex);
    75.         }
    76.  
    77.  
    78.         public void Next()
    79.         {
    80.             s_SelectedIndex++;
    81.             if (s_SelectedIndex == demoParticles.items.Length)
    82.             {
    83.                 s_SelectedIndex = 0;
    84.             }
    85.             Select(s_SelectedIndex);
    86.         }
    87.  
    88.  
    89.         private void Update()
    90.         {
    91.  
    92. #if !MOBILE_INPUT
    93.             KeyboardInput();
    94. #endif
    95.  
    96.  
    97.  
    98.             sceneCamera.localPosition = Vector3.SmoothDamp(sceneCamera.localPosition, Vector3.forward*-s_Selected.camOffset,
    99.                                                        ref m_CamOffsetVelocity, 1);
    100.  
    101.             if (s_Selected.mode == Mode.Activate)
    102.             {
    103.                 // this is for a particle system that just needs activating, and needs no interaction (eg, duststorm)
    104.                 return;
    105.             }
    106.  
    107.             if (CheckForGuiCollision()) return;
    108.  
    109.             bool oneShotClick = (Input.GetMouseButtonDown(0) && s_Selected.mode == Mode.Instantiate);
    110.             bool repeat = (Input.GetMouseButton(0) && s_Selected.mode == Mode.Trail);
    111.  
    112.             if (oneShotClick || repeat)
    113.             {
    114.                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    115.                 RaycastHit hit;
    116.                 if (Physics.Raycast(ray, out hit))
    117.                 {
    118.                     var rot = Quaternion.LookRotation(hit.normal);
    119.  
    120.                     if (s_Selected.align == AlignMode.Up)
    121.                     {
    122.                         rot = Quaternion.identity;
    123.                     }
    124.  
    125.                     var pos = hit.point + hit.normal*spawnOffset;
    126.  
    127.                     if ((pos - m_LastPos).magnitude > s_Selected.minDist)
    128.                     {
    129.                         if (s_Selected.mode != Mode.Trail || m_Instance == null)
    130.                         {
    131.                             m_Instance = (Transform) Instantiate(s_Selected.transform, pos, rot);
    132.  
    133.                             if (m_ParticleMultiplier != null)
    134.                             {
    135.                                 m_Instance.GetComponent<ParticleSystemMultiplier>().multiplier = multiply;
    136.                             }
    137.  
    138.                             m_CurrentParticleList.Add(m_Instance);
    139.  
    140.                             if (s_Selected.maxCount > 0 && m_CurrentParticleList.Count > s_Selected.maxCount)
    141.                             {
    142.                                 if (m_CurrentParticleList[0] != null)
    143.                                 {
    144.                                     Destroy(m_CurrentParticleList[0].gameObject);
    145.                                 }
    146.                                 m_CurrentParticleList.RemoveAt(0);
    147.                             }
    148.                         }
    149.                         else
    150.                         {
    151.                             m_Instance.position = pos;
    152.                             m_Instance.rotation = rot;
    153.                         }
    154.  
    155.                         if (s_Selected.mode == Mode.Trail)
    156.                         {
    157.                             var emission = m_Instance.transform.GetComponent<ParticleSystem>().emission;
    158.                             emission.enabled = false;
    159.                             m_Instance.transform.GetComponent<ParticleSystem>().Emit(1);
    160.                         }
    161.  
    162.                         m_Instance.parent = hit.transform;
    163.                         m_LastPos = pos;
    164.                     }
    165.                 }
    166.             }
    167.         }
    168.  
    169.  
    170. #if !MOBILE_INPUT
    171.         void KeyboardInput()
    172.         {
    173.             if(Input.GetKeyDown(KeyCode.LeftArrow))
    174.                 Previous();
    175.  
    176.             if (Input.GetKeyDown(KeyCode.RightArrow))
    177.                 Next();
    178.         }
    179. #endif
    180.  
    181.  
    182.         bool CheckForGuiCollision()
    183.         {
    184.             PointerEventData eventData = new PointerEventData(eventSystem);
    185.             eventData.pressPosition = Input.mousePosition;
    186.             eventData.position = Input.mousePosition;
    187.  
    188.             List<RaycastResult> list = new List<RaycastResult>();
    189.             graphicRaycaster.Raycast(eventData, list);
    190.             return list.Count > 0;
    191.         }
    192.  
    193.         private void Select(int i)
    194.         {
    195.             s_Selected = demoParticles.items[i];
    196.             m_Instance = null;
    197.             foreach (var otherEffect in demoParticles.items)
    198.             {
    199.                 if ((otherEffect != s_Selected) && (otherEffect.mode == Mode.Activate))
    200.                 {
    201.                     otherEffect.transform.gameObject.SetActive(false);
    202.                 }
    203.             }
    204.             if (s_Selected.mode == Mode.Activate)
    205.             {
    206.                 s_Selected.transform.gameObject.SetActive(true);
    207.             }
    208.             m_ParticleMultiplier = s_Selected.transform.GetComponent<ParticleSystemMultiplier>();
    209.             multiply = 1;
    210.             if (clearOnChange)
    211.             {
    212.                 while (m_CurrentParticleList.Count > 0)
    213.                 {
    214.                     Destroy(m_CurrentParticleList[0].gameObject);
    215.                     m_CurrentParticleList.RemoveAt(0);
    216.                 }
    217.             }
    218.  
    219.             instructionText.text = s_Selected.instructionText;
    220.             titleText.text = s_Selected.transform.name;
    221.         }
    222.  
    223.  
    224.         [Serializable]
    225.         public class DemoParticleSystem
    226.         {
    227.             public Transform transform;
    228.             public Mode mode;
    229.             public AlignMode align;
    230.             public int maxCount;
    231.             public float minDist;
    232.             public int camOffset = 15;
    233.             public string instructionText;
    234.         }
    235.  
    236.         [Serializable]
    237.         public class DemoParticleSystemList
    238.         {
    239.             public DemoParticleSystem[] items;
    240.         }
    241.     }
    242. }
    243.  
    244.  
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I never used the particle system, but you'll have to import it like most other things as well. If you use visual studio, that should be one of the things it recommends you when you click on the word "Particle", which should have a red squiggly line under it. You can then import the corresponding package.
    However, in my search at least i couldnt find any property called "SystemMultiplier" related to particles. Are you sure that's something that even exists?
     
    johnwellard360 likes this.
  3. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    I have no idea if this exists because i didnt change this script at all. I cant find the import and "Particle" have not the red line under i have no idea what to do :/.
     
    kzmgy likes this.
  4. Where did you get this script?

    Because I think the 42. line should be
    Code (CSharp):
    1. private ParticleSystemMultiplier m_ParticleMultiplier;
     
  5. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    I have on idea, i got it when i added my assets and have no idea how to find out which asset was that.

    When i add this line i have this error:
    Assets\SampleScenes\Scripts\ParticleSceneControls.cs(42,17): error CS0246: The type or namespace name 'ParticleSystemMultiplier' could not be found (are you missing a using directive or an assembly reference?)
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
  7. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    It fix the error CS0246 but i got new one :/

    Assets\Flooded_Grounds\PostProcessing\Editor\PropertyDrawers\MinDrawer.cs(6,34): error CS0104: 'MinAttribute' is an ambiguous reference between 'UnityEngine.PostProcessing.MinAttribute' and 'UnityEngine.MinAttribute'


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.PostProcessing;
    3.  
    4. namespace UnityEditor.PostProcessing
    5. {
    6.     [CustomPropertyDrawer(typeof(MinAttribute))]
    7.     sealed class MinDrawer : PropertyDrawer
    8.     {
    9.         public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    10.         {
    11.             MinAttribute attribute = (MinAttribute)base.attribute;
    12.  
    13.             if (property.propertyType == SerializedPropertyType.Integer)
    14.             {
    15.                 int v = EditorGUI.IntField(position, label, property.intValue);
    16.                 property.intValue = (int)Mathf.Max(v, attribute.min);
    17.             }
    18.             else if (property.propertyType == SerializedPropertyType.Float)
    19.             {
    20.                 float v = EditorGUI.FloatField(position, label, property.floatValue);
    21.                 property.floatValue = Mathf.Max(v, attribute.min);
    22.             }
    23.             else
    24.             {
    25.                 EditorGUI.LabelField(position, label.text, "Use Min with float or int.");
    26.             }
    27.         }
    28.     }
    29. }
    30.  
     
  8. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    The compiler does not know whether you are talking about UnityEngine.PostProcessing.MinAttribute (since it's imported) or just UnityEngine.MinAttribute (since it's imported), so you need to make it clear by writing the full name for the one you intended to use. And wil full name i mean as it is written in the error message, so including the package it comes from.
     
  9. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    Ok ty guys it works now :)
     
  10. DusselEins

    DusselEins

    Joined:
    Jan 30, 2020
    Posts:
    1
    im having trouble myself. my issue has this error:
    Assets\scenes\scripts\enemy1.cs(25,13): error CS0246: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
    here's the code:
    Code (CSharp):
    1.   public void Damage()
    2.     {
    3.         _lives--;
    4.  
    5.         if (_lives < 1)
    6.         {
    7.             Destroy(this.gameObject);
    8.         }
    and:
    Code (CSharp):
    1.  if (other.tag == "Player")
    2.         {
    3.             Player player = other.transform.GetComponent<Player>();
    4.  
    5.             if (player != null)
    6.             {
    7.                 player.Damage();
    8.             }
    9.  
    10.             Destroy(this.gameObject);
    11.         }
    12.  
    13.         if (other.tag == "laser")
    14.         {
    15.             Destroy(other.gameObject);
    16.             Destroy(this.gameObject);
    17.         }
    18.     }
    19. }
    im using a professional (now over $100) tutorial but I cant think of a way to fix this. any help? pls answer quickly....
     
  11. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Better go back to your tutorial then. The simple explanation is it can't find the Player class. Either you haven't created it or it's under a namespace. Unfortunately, nobody can tell you which. So go through your tutorial again.
     
    Yoreki likes this.
  12. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    Code (CSharp):
    1. public class PlayerMovment : MonoBehaviour
    2. {
    3.  
    4.     public CharacterController controller;
    5.  
    6.  
    7.     public float speed = 12f;
    8.     public float gravity = -9.81;
    9.  
    10.     Vector3 velocity;
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         float x = Input.GetAxis("Horizontal");
    16.  
    17.         float z = Input.GetAxis("Vertical");
    18.  
    19.         Vector3 move = transform.right * x + transform.forward * z;
    20.  
    21.         controller.Move(move * speed * Time.deltaTime);
    22.  
    23.         velocity.y += gravity * Time.deltaTime;
    24.  
    25.         controller.Move(velocity * Time.deltaTime);
    26.  
    27.  
    28.  
    29.     }
    30. }
    31.  
    i have no idea i have 3 errors and they are saying this error CS0246
     
  13. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Please do not necro-post old threads to fix your own typos. These are literally JUST TYPOS.

    Here is how to fix your own typos:

    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.
     
  14. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    i fixed it it was because it was to many files lol