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

Help with error CS0246

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

  1. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    Hello im new in Unity and i cant find solution for this error:

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

    the line that i have problem with is public ParticleSystemMultiplier m_ParticleMultiplier;
    Do anyone know how to fix it.


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

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Looks like you need this line:
    using UnityStandardAssets.Effects;
     
  3. dax005

    dax005

    Joined:
    Sep 14, 2019
    Posts:
    7
    If i add this line i get 2 errors

    Assets\SampleScenes\Scripts\ParticleSceneControls.cs(6,27): error CS0234: The type or namespace name 'Effects' does not exist in the namespace 'UnityStandardAssets' (are you missing an assembly reference?)

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

    oriondeyoe

    Joined:
    Aug 6, 2020
    Posts:
    1
    I am also having this exact error. Is there a fix?
     
  5. Moerte86

    Moerte86

    Joined:
    Mar 1, 2020
    Posts:
    1
    I having exactly the same error on ParticleSceneControl.
    Can someone help with this?
     
  6. Chumbinho_Codder

    Chumbinho_Codder

    Joined:
    Sep 14, 2020
    Posts:
    2
    u need to optimize this code. this S*** is giant
     
  7. DawnedNite

    DawnedNite

    Joined:
    Oct 18, 2020
    Posts:
    1
    Make sure you import the effects and Physics Material when you do your import
     
  8. TheCreatorTT2021

    TheCreatorTT2021

    Joined:
    Sep 9, 2021
    Posts:
    2
    i have the same problem and I have try to insert using UnityStandardAssets.Effects; but the problems still occurs.
     
  9. TheCreatorTT2021

    TheCreatorTT2021

    Joined:
    Sep 9, 2021
    Posts:
    2
  10. YousafGrewal

    YousafGrewal

    Joined:
    Jul 5, 2018
    Posts:
    17
    Adding below line helped me:
    using UnityStandardAssets.ImageEffects;