Hi everyone
I have this set up so when the user clicks with right mouse button a little menu pops up with an opacity slider and a few buttons to change the selected objects texture.
The texture works fine. It only changes on the object which has been right mouse clicked. However the opacity changes on ALL objects this script is attached to. How do I make the opacity affect only the selected object?
Please help.
Thanks
//the colider
var target: Transform;
//the object
var selected: GameObject;
var posx: int;
var posy: int;
var ObjectName: String;
var visible;
//opacity changer
static var slider : float;
//texture changer
var no = 0;
var textures : TextureArray = selected.GetComponent(TextureArray);
function Start () {
slider = 1.0;
slider = selected.renderer.material.color.a;
}
function OnGUI()
{
if( visible )
{
mywindow = GUI.Window (0, (Rect (posx, Screen.height - posy, 110, 120)), WindowFunction, ObjectName);
}
}
function Update () {
selected.renderer.material.color.a = slider;
if (Input.GetKey(KeyCode.LeftAlt))
{
}
else
{
if (Input.GetMouseButtonDown(1))
{
posx = Input.mousePosition.x;
posy = Input.mousePosition.y;
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if (Physics.Raycast(ray, hit)) {
if (hit.transform == target) {
visible=!visible;
}
}
}
}
}
function WindowFunction (windowID : int) {
//On-Off button
if (GUI.Button(Rect(90,0,14,14),"", "toggle")) {
visible = false;
}
//Left texture button
if (GUI.Button(Rect(10,20,40,20), "<<")) {
no += 1;
if (no >=textures.textures.length) { no = 0; }
selected.renderer.material.mainTexture = textures.textures[no];
}
//Right texture button
if (GUI.Button(Rect(60,20,40,20), ">>")) {
no -= 1;
if (no <=-textures.textures.length) { no = 0; }
selected.renderer.material.mainTexture = textures.textures[no];
}
slider = GUI.HorizontalSlider ( Rect(10,45,90,20), slider, 0, 1.0);
//Second button
if (GUI.Button(Rect(10,65,90,20), "SOMETHING")) {
}
//Third button
if (GUI.Button(Rect(10,90,90,20), "SOMETHING")) {
}
//Fourth button
if (GUI.Button(Rect(10,115,90,20), "SOMETHING")) {
}
GUI.DragWindow ();
}