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 Error CS0246

Discussion in 'Scripting' started by pixtongames, Jun 12, 2023.

  1. pixtongames

    pixtongames

    Joined:
    Jan 22, 2022
    Posts:
    2
    I am trying to reference another script as a component of a game object. I put in the name of the script but it doesn't wanna work and it is giving me six errors.
    Assets\Scripts\CollisionForGlitch.cs(76,33): error CS0246: The type or namespace name 'AnalogGlitch' could not be found (are you missing a using directive or an assembly reference?)
    Assets\Scripts\CollisionForGlitch.cs(76,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
    The other four errors are the same things but for lines 77 and 78.

    This is the script:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class CollisionForGlitch : MonoBehaviour
    5. {
    6.     [SerializeField] float levelLoadDelay = 2f;
    7.     [SerializeField] AudioClip crash;
    8.     [SerializeField] AudioClip success;
    9.  
    10.     [SerializeField] ParticleSystem crashParticles;
    11.     [SerializeField] ParticleSystem successParticles;
    12.  
    13.     AudioSource audioSource;
    14.  
    15.     bool isTransitioning = false;
    16.     bool toggleCollision = true;
    17.     GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
    18.  
    19.     void Start () {
    20.         audioSource = GetComponent<AudioSource>();
    21.         toggleCollision = true;
    22.     }
    23.  
    24.     void Update ()
    25.     {
    26.         RespondToDebugKeys();
    27.     }
    28.  
    29.     private void RespondToDebugKeys()
    30.     {
    31.         if (Input.GetKey(KeyCode.L))
    32.         {
    33.             Invoke("LoadNextLevel", 0);
    34.         }
    35.         else if (Input.GetKey(KeyCode.C))
    36.         {
    37.             if (toggleCollision == true)
    38.             {
    39.                 toggleCollision = false;
    40.                 if (toggleCollision == false) {
    41.                     Debug.Log("Collision off");
    42.                 }
    43.             }
    44.             else
    45.             {
    46.                 toggleCollision = true;
    47.                 if (toggleCollision == true) {
    48.                     Debug.Log("Collision on");
    49.                 }
    50.             }
    51.         }
    52.     }
    53.  
    54.     private void OnCollisionEnter(Collision other) {
    55.         if (isTransitioning || toggleCollision == false) { return; }
    56.  
    57.         switch (other.gameObject.tag) {
    58.             case "Friendly":
    59.                 Debug.Log("We hit our safe zone we are now ready to thrust.");
    60.                 break;
    61.             case "Finish":
    62.                 StartSuccessSequence();
    63.                 break;
    64.             default:
    65.                 StartCrashSequence();
    66.                 Debug.Log("Brace for impact, we are about to crash into--");
    67.                 break;
    68.         }
    69.     }
    70.  
    71.     void StartSuccessSequence() {
    72.         isTransitioning = true;
    73.         audioSource.Stop();
    74.         audioSource.PlayOneShot(success);
    75.         successParticles.Play();
    76.         mainCamera.GetComponent<AnalogGlitch>()._scanLineJitter == 0.35;
    77.         mainCamera.GetComponent<AnalogGlitch>()._verticalJump == 0.3;
    78.         mainCamera.GetComponent<AnalogGlitch>()._colorDrift == 0.06;
    79.         GetComponent<Movement>().enabled = false;
    80.         Debug.Log("We have now reached our designated location.");
    81.         Invoke ("LoadNextLevel", levelLoadDelay);
    82.     }
    83.     void StartCrashSequence() {
    84.         isTransitioning = true;
    85.         audioSource.Stop();
    86.         audioSource.PlayOneShot(crash);
    87.         crashParticles.Play();
    88.         GetComponent<Movement>().enabled = false;
    89.         Invoke ("ReloadLevel", 1f);
    90.    
    91.     }
    92.  
    93.     void LoadNextLevel() {
    94.         int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    95.         int nextSceneIndex = currentSceneIndex + 1;
    96.         if (nextSceneIndex == SceneManager.sceneCountInBuildSettings) {
    97.             nextSceneIndex = 0;
    98.         }
    99.         SceneManager.LoadScene(nextSceneIndex);
    100.         Debug.Log("NEXT");
    101.     }
    102.     void ReloadLevel() {
    103.         int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    104.         SceneManager.LoadScene(currentSceneIndex);
    105.     }
    106. }
    107.  
    And this is the script I am trying to reference:
    Code (CSharp):
    1. //
    2. // KinoGlitch - Video glitch effect
    3. //
    4. // Copyright (C) 2015 Keijiro Takahashi
    5. //
    6. // Permission is hereby granted, free of charge, to any person obtaining a copy of
    7. // this software and associated documentation files (the "Software"), to deal in
    8. // the Software without restriction, including without limitation the rights to
    9. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
    10. // the Software, and to permit persons to whom the Software is furnished to do so,
    11. // subject to the following conditions:
    12. //
    13. // The above copyright notice and this permission notice shall be included in all
    14. // copies or substantial portions of the Software.
    15. //
    16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    18. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    19. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    20. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    21. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    22. //
    23. using UnityEngine;
    24.  
    25. namespace Kino
    26. {
    27.     [ExecuteInEditMode]
    28.     [RequireComponent(typeof(Camera))]
    29.     [AddComponentMenu("Kino Image Effects/Analog Glitch")]
    30.     public class AnalogGlitch : MonoBehaviour
    31.     {
    32.         #region Public Properties
    33.  
    34.         // Scan line jitter
    35.  
    36.         [SerializeField, Range(0, 1)]
    37.         float _scanLineJitter = 0;
    38.  
    39.         public float scanLineJitter {
    40.             get { return _scanLineJitter; }
    41.             set { _scanLineJitter = value; }
    42.         }
    43.  
    44.         // Vertical jump
    45.  
    46.         [SerializeField, Range(0, 1)]
    47.         float _verticalJump = 0;
    48.  
    49.         public float verticalJump {
    50.             get { return _verticalJump; }
    51.             set { _verticalJump = value; }
    52.         }
    53.  
    54.         // Horizontal shake
    55.  
    56.         [SerializeField, Range(0, 1)]
    57.         float _horizontalShake = 0;
    58.  
    59.         public float horizontalShake {
    60.             get { return _horizontalShake; }
    61.             set { _horizontalShake = value; }
    62.         }
    63.  
    64.         // Color drift
    65.  
    66.         [SerializeField, Range(0, 1)]
    67.         float _colorDrift = 0;
    68.  
    69.         public float colorDrift {
    70.             get { return _colorDrift; }
    71.             set { _colorDrift = value; }
    72.         }
    73.  
    74.         #endregion
    75.  
    76.         #region Private Properties
    77.  
    78.         [SerializeField] Shader _shader;
    79.  
    80.         Material _material;
    81.  
    82.         float _verticalJumpTime;
    83.  
    84.         #endregion
    85.  
    86.         #region MonoBehaviour Functions
    87.  
    88.         void OnRenderImage(RenderTexture source, RenderTexture destination)
    89.         {
    90.             if (_material == null)
    91.             {
    92.                 _material = new Material(_shader);
    93.                 _material.hideFlags = HideFlags.DontSave;
    94.             }
    95.  
    96.             _verticalJumpTime += Time.deltaTime * _verticalJump * 11.3f;
    97.  
    98.             var sl_thresh = Mathf.Clamp01(1.0f - _scanLineJitter * 1.2f);
    99.             var sl_disp = 0.002f + Mathf.Pow(_scanLineJitter, 3) * 0.05f;
    100.             _material.SetVector("_ScanLineJitter", new Vector2(sl_disp, sl_thresh));
    101.  
    102.             var vj = new Vector2(_verticalJump, _verticalJumpTime);
    103.             _material.SetVector("_VerticalJump", vj);
    104.  
    105.             _material.SetFloat("_HorizontalShake", _horizontalShake * 0.2f);
    106.  
    107.             var cd = new Vector2(_colorDrift * 0.04f, Time.time * 606.11f);
    108.             _material.SetVector("_ColorDrift", cd);
    109.  
    110.             Graphics.Blit(source, destination, _material);
    111.         }
    112.         #endregion
    113.     }
    114. }
    115.  
    No clue what's going on here, it would be great if someone could help.

    Update: I changed the == on lines 76-78 into just =, and it removed error CS0201. The other error is still showing up.
     
    Last edited: Jun 13, 2023
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,082
    See the namespace line in the KinoGlitch script? You need to have a using statement in the script trying to use the contents of the namespace that matches it (ie
    using Kino;
    ).
     
    pixtongames likes this.
  3. pixtongames

    pixtongames

    Joined:
    Jan 22, 2022
    Posts:
    2
    Thanks, it worked. Thank you so much lol