- Home /
Draw a waveform on a mobile texture
Hello there. I want to draw an outputting sound waveform on a texture that is supposed to move with a given 2D GameObject 'A' (typically to be drawn upper the head of a character). As I want this texture to be a prefab afterward (I want to display it above many other characters) it would be very convenient for me to make it a child of 'A'. Right now, what I'm doing is to draw the waveform on a GUITexture, created as a child of 'A'. However, as you already know, the location of the GUITexture is different from the other GameObjects (positions are scaled between 0 and 1), and cannot move properly with its parent. As far as I can see, whatever the solution I choose (keeping it as a child of 'A' or not), I will have to manipulate the transform.location and the Pixel Insets in a very inconvenient way, whereas it would be very simple with another type of object, being a simple child of 'A'. I hope I'm clear.
My question is the following: is there any way to put back the GuiTexture transform.position to a normal scale ? If not, can I use another type of object to draw inside dynamically ? I was hoping I could do it in an empty sprite, but I can't find anything about this on the internet...
Answer by robertbu · Oct 29, 2014 at 04:35 AM
I read your question when it first came across the list and again just now. I'm still not sure I understand. My suggestion is to do the following:
Place an empty game object where the position where you want your GUITexture
Make that empty game object a child of the object that is currently the parent of your GUITexture
Don't make the GUITexture a child
Attach the following script to the GUITexture:
#pragma strict
var toFollow : Transform;
function LateUpdate() {
transform.position = Camera.main.WorldToViewportPoint(toFollow);
}
You would initialize toFollow by draging and dropping the empty 'marker' game object on the 'toFollow' variable. Note that you would not manipulate 'pixelInset'.
Apparently you understood well because it works, thank you! But in that case, I don't really understand why I need the empty object. I tried to initialize 'toFollow' directly with the parent, and it also works. Anyway, thanks a lot for your help :)
The parent will work as long as the position you are trying to match is the parent's position. Typically with this kind of thing, people are trying to offset the result to be above or below some world position. Think health meter floating over a character for example.
Yeah right, in my case it works, but I'll keep that in $$anonymous$$d. Thanks again for the clarification!
Your answer
Follow this Question
Related Questions
5.1 Channels is backwards in unity (non 3D) 0 Answers
Audio Settings Menu 2 Answers
play sound when moving stop sound when not 1 Answer
Why is my backtrack's volume getting lower? 0 Answers
3D Sound Max Distance Not Working. 0 Answers