x


GUI slider and rotation not working

Hi, everyone, I'm working on an RTS, and I want the player to be able to edit the rotation of the buildings that he got. My building works like this: [Parent Object, with the appropriate name] [model w/ mesh collider] [any other gameobjects for the building]

This script is attatched to the building:

enum TypeOfBuilding
{
    House,
    Forge,
    SoldireHouse,
    Castle,
    OtherObject
}   
var typeOfBuilding : TypeOfBuilding;
var health : int;
var Name : String;
var selectedColor : Color;
class SoldireHouseVars 
{
    var creationRate : float;
    var Soldire : GameObject;
    var creationPoint : GameObject;
}
var SoldireHouseVars : SoldireHouseVars = SoldireHouseVars;

@HideInInspector
var hSliderValue : float = 0.0;

private var showBox : boolean = false;
private var showStats : boolean = false;
private var lastCreation : float;

function Update()
{
    if(typeOfBuilding == TypeOfBuilding.SoldireHouse)
    {
        if(Time.time > lastCreation)
        {
            lastCreation = Time.time + SoldireHouseVars.creationRate;
            var go : GameObject = Instantiate(SoldireHouseVars.Soldire, SoldireHouseVars.creationPoint.transform.position, transform.rotation);
            go.AddComponent(Soldire);
        }
    }
}

function OnMouseOver () 
{
    if(showBox != true)
    {
        showBox = true;
    }
    if(Input.GetMouseButtonDown(0))
    {
        showStats = true;
    }
}
function OnMouseExit () 
{
    if(showBox == true)
    {
        showBox = false;
    }
}
function OnGUI()
{
    if(showBox)
    {
        GUI.Label(Rect(5, 5, 200, 30), typeOfBuilding.ToString());
    }
    if(showStats)
    {
        Time.timeScale = 0;
        GUI.Box(Rect(Screen.width-150, 0, 150, Screen.height), Name);
        if(GUI.Button(Rect(Screen.width-150, Screen.height-40, 150, 20), "Delete"))
        {
            Destroy(gameObject);
            Time.timeScale = 1;
        }
        if(GUI.Button(Rect(Screen.width-150, Screen.height-20, 150, 20), "Done"))
        {
            Time.timeScale = 1;
            showStats = false;
            transform.rotation.y = hSliderValue;
        }
        hSliderValue = GUI.HorizontalSlider (Rect (Screen.width-140, 30, 135, 30), hSliderValue, 0.0, 360.0);
    }
} 
function GetName()
{
    return(Name);
}

The GUI slider is my problem. When I set it, unless it is up against the very edge (at 0), it is 180 degrees. I want it to be at the value of the slider. How would I do this?

Thanks for the help!!! :)

more ▼

asked Mar 12 '11 at 01:45 PM

zmar0519 gravatar image

zmar0519
946 59 66 78

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3694
x2173
x156
x103
x19

asked: Mar 12 '11 at 01:45 PM

Seen: 770 times

Last Updated: Mar 12 '11 at 01:45 PM