Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mohamedhassan · Mar 19, 2015 at 12:16 PM · scripting problemvideo game

video code not playing

hi, i make c code to play video in unity3d but not working and appear this error what can i do

An object reference is required to access non-static member `UnityEngine.Material.mainTexture'

and this my code

using UnityEngine; using System.Collections;

[RequireComponent (typeof (AudioSource))]

public class video : MonoBehaviour {

 public MovieTexture movie;

 // Use this for initialization
 void Start () 
 {
     Renderer.material.mainTexture = movie as MovieTexture;
     movie.Play ();
 }

}

and also in javascript this code not work

renderer.material.mainTexture.play();

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sujit11dec · Mar 19, 2015 at 03:24 PM

[RequireComponent (typeof(AudioSource))]

public class VideoPlay : MonoBehaviour {

 public MovieTexture movie;
 
 void Start () {
     renderer.material.mainTexture = movie as MovieTexture;
     audio.clip = movie.audioClip;
     movie.Play ();
     audio.Play ();
 }
 
 
 void Update () {
 
 }

}

Try this code

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mohamedhassan · Mar 20, 2015 at 05:54 AM 0
Share

not work too and appear this message

UnityEngine.Component.renderer' is obsolete: `Property renderer has been deprecated. Use GetComponent() ins$$anonymous$$d. (UnityUpgradable)'

avatar image mohamedhassan · Mar 22, 2015 at 11:12 AM 0
Share

thanks but it tell me that android not support the $$anonymous$$ovieTexture so i use this code and also not work ...

function Start () { Handheld.PlayFullScreen$$anonymous$$ovie ("StarWars.mp4", Color.black, FullScreen$$anonymous$$ovieControl$$anonymous$$ode.CancelOnInput); }

my project is very simple ... video work on plane or cube so i need the right script to export this video to play on android phone thanks very much

avatar image
0

Answer by Johat · Mar 22, 2015 at 01:28 PM

I just noticed in the comments that you're wanting to do this on Android. You should really try to include such details in your question as it effects the answer!

As far as I can tell, this is not a supported feature on Android. There are workarounds though.

The Unity docs seem to give everything you should need to know: MovieTexture Manual and Handheld.PlayFullScreenMovie.

Hope that helps. I'll leave my answer below this as it answers the question as you've asked it.

==================================================================

Your problem is that you're trying to access the renderer's material as if it is a static variable (belongs to the class), when it is an instance variable (belongs to the instance).

What you want to do is use GetComponent() to get the Renderer you're after (there will certainly be many Renderers in your scene, which is why you have to get the instance rather than the whole class). It wouldn't make sense for the material properties to be static features of the Renderer class!

sujit11dec is along to right tracks, and his solution will work in older versions of Unity. However, in Unity 5 they removed some "shortcuts" to accessing components (which deceptively look like variables).

Here:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(AudioSource))]
 public class video : MonoBehaviour {
 
  public MovieTexture movie;
  
  // Use this for initialization
  void Start () 
  {
      GetComponent<Renderer>().material.mainTexture = movie as MovieTexture;
      movie.Play();
  }
 }

It might be worth reading up on classes and static variables/functions. It's reasonably simple (and key/core!) stuff, but you might find it helpful to get a better grasp of some of the core concepts for future work.

Hope that all works out for you =).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

playerprefs spawning errors. 1 Answer

Use vim with unity? 1 Answer

2D game kit Door isn't opening 3 Answers

Rotating objects in local space? 1 Answer

How can I make that the waiting time in StartCoroutine will take effect when changing the value in inspector when the game is running ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges