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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

error CS0246 missing type or namespace...

Discussion in 'Scripting' started by commiga, Dec 12, 2015.

  1. commiga

    commiga

    Joined:
    Oct 6, 2015
    Posts:
    2
    I have an error CS0246. I can't figure why it won't recognize my references. I'm sure the names are correct because I've copied and pasted the names. It recognizes one reference but doesn't like the other references. I'm new to C# so I could be doing this all wrong.
    Any advice would be useful.

    Best Regards,
     

    Attached Files:

  2. 3zzerland

    3zzerland

    Joined:
    Oct 31, 2014
    Posts:
    42
    In the visible code (which I reposted below) there are 0 errors. So we may need more details.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MovieText : MonoBehaviour {
    5.  
    6.   public MovieTexture video;
    7.   private AudioSource ses;
    8.  
    9.     void Start () {
    10.      GetComponent<Renderer>().material.mainTexture = video as MovieTexture;
    11.      ses = GetComponent<AudioSource>();
    12.      video.Play();
    13.     }
    14.  
    15. }
     
  3. RavenMikal

    RavenMikal

    Joined:
    Oct 18, 2014
    Posts:
    144
    and the full error, normally tells you what line its on <_<
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    from the pic, he trying to build to Android platform, and it's complaining about line "7" which is line 6 in @3zzerland 's repost. @commiga please include the actual details of the problem when posting and asking for help. You don't mention that this error is coming up when you build for a specific platform (given the reason below, it will have worked fine during testing within the editor), you haven't posted the code in an easily readable fashion. Pics are nice, but we can't copy/paste/test a pic. When you post code to the forums, use the code tags http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    http://docs.unity3d.com/Manual/class-MovieTexture.html
     
    Kiwasi and 3zzerland like this.
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,985
    Line 10. You are not calling getComponent on anything.
     
  6. 3zzerland

    3zzerland

    Joined:
    Oct 31, 2014
    Posts:
    42
    @LeftyRighty already answered the question. There is nothing wrong with his GetComponent call.
     
    zombiegorilla likes this.
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Nice catch

    GetComponent is a member of MonoBehaviour. So calling GetComponent like this is the equivalent of this.GetComponent or gameObject.GetComponent. It just takes less typing.
     
    zombiegorilla likes this.
  8. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,985
    Ah, missed that. Still, looks strange without an assignment or object. ;)
     
    Kiwasi likes this.
  9. commiga

    commiga

    Joined:
    Oct 6, 2015
    Posts:
    2
    Thanks for your answers. I want to built it in android platform. I will try your suggestion and share results.