- Home /
hide different planes, renderers issue
Hi,
i would like to create an animated texture, i would like to create 15 planes, add a texture to each of them, and hide them one after the other to fake the animation. This code does not work because it says "NullReferenceException: Object reference not set to an instance of an object", i have put 2 planes with a mesh renderer (set automatically) in an empty object named "AT", then i created a script linked to the camera, or to the AT object (in this case, i changed "at" with "this" ) :
//private var at : GameObject;
private var renderers : Renderer[];
function Start () {
//at = GameObject.Find("AT");
//renderers = at.GetComponentsInChildren(Renderer);
//renderers = GetComponentsInChildren(Renderer);
renderers = this.GetComponentsInChildren(Renderer);
}
function Update () {
for (var r : Renderer in renderers) { /* NullReferenceException */
r.enabled = !r.enabled;
}
}
Would you know how to achieve this?
Thanks
Answer by robertbu · Feb 14, 2013 at 04:26 PM
If you are trying to "fake" an animation, you can create a single plane and change the texture on that plane. There is some source here:
http://answers.unity3d.com/questions/392517/introduction-movie.html
As for your code above, did you check to see if 'renderers' is null?
thanks, each image has a 512x512 resolution, and i have 15 frames + 20 frames (a second animated texture), i think this will add a lot of draw calls if i don't use a texture atlas, but can i use a texture atlas with so many textures? This is why i headed to the planes (all the planes in a single object so that i can use 1 draw call with a script) 2/ how could i cast it? i tried "length" but it says "InvalidCastException: Cannot cast from source type to destination type."
The code above will only generate one draw call since only one texture is displayed in any one frame.
The limit to a texture atlas is not number of "subtextures," but total size. It can have any number of object as long as they fit on the texture. For an iPad the maximum atlas size is 4$$anonymous$$ x 4$$anonymous$$, so it could contain up to 64 of your 512 x 512 images.
We use EZGUI for our interface work, and their PackedSprite class would allow you to simply drag your textures into their Timeline editor and your animation would be done. But the code above will do the job.
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
How do I make different gameobjects appear, every time you click the GUI.button? 2 Answers
Unity 2019.4.9f1 - Toggle Show/Hide Gameobject with one keystroke. 1 Answer
Object being covered by a plane below it 0 Answers
Duplicate everything in a set space in all directions? 2 Answers