Have no idea why i keep getting errors when i follow tutorials exactly how they do it but mine never works lol. I am trying to have the sphere hidden when game starts but then activates when i hit a button on my touch controllers.
Here is the error code.
cheers
GameObject Sphere;
// Use this for initialization
void Start () {
Sphere.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (OVRInput.Get(OVRInput.Button.One))
{
Sphere.SetActive(true);
}
}
}
i fixed it i had one extra } at the bottom. i still can’t manage to get the oculus controller to activate the sphere though and the sphere at the start is not being deactivated even though the code is telling it to.
in the script you posted (btw, please look at this for how to post code on the forums : Using code tags properly - Unity Engine - Unity Discussions), the Sphere gameobject is private, so how is that assigned?
Did you type it differently here ?
If that’s exactly how your project is, you want to try maybe setting public or the attribute “SerializeField” and then drag/drop the sphere game object into the script in the inspector.
Thank you methos5k, i will read through that anyways i ended up sorting it, What i did not do was after assigning the GameObject to Sphere i did not know you had to drag the sphere inside unity to the inspector aswell. its tough but exciting work lol
just one quick one and i have really looked on the net but with no luck i can get an object to scale up but how can i set a maximum value so it stops scaling once a value is hit. Here is the code i am using to scale between .001 but would like it to stop at .1.
this.Sphere.transform.localScale += new Vector3(.001f, .001f, .001f);
So as to not confuse things, I won’t describe fully this next comment, but if your scaling just goes up at an event (or just once), it could be “slightly better” to do it in a coroutine. It’s a little more organized, b/c then Update code is not always running, when not needed. For a small thing like this, and just learning, it’s no big deal… nothing to worry about
thank you again, the scale happens everytime i press a button, so if i hold button a it keeps scaling until i let go but i wanted it to stop at a certain value no matter how long i hold the button, once i let go of the button it disappears. I have all this working apart from the maximum scale value as it just keeps getting bigger and bigger with no limit lol.
public GameObject Sphere;
public float scaleValue = .001f;
// Use this for initialization
void Start()
{
Sphere.SetActive(false);
}
// Update is called once per frame
void Update()
{
scaleValue += .001f;
scaleValue = Mathf.Clamp(scaleValue, .001f, 1f);
Sphere.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);
if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger))
{
if (OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger))
Sphere.SetActive(true);
}
else
Sphere.SetActive(false);
}
}
Okay, so first just to confirm this script is on an object that is not the sphere.
Then, I had to use mouse buttons instead of your OVRInput, because I don’t have that.
Here’s what I did:
void Update()
{
if (Input.GetMouseButton(0))
{
if (Input.GetMouseButton(1))
{
Sphere.SetActive(true);
scaleValue += .001f;
scaleValue = Mathf.Clamp(scaleValue, .001f, 1f);
Sphere.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);
}
}
else
Sphere.SetActive(false);
}
So, here we have the scale going up so long as both buttons are held down (and the sphere is active).
If both buttons aren’t down, it’s inactive (and also not scaling up).
It respects the bounds – doesn’t scale higher than 1,1,1.
its working now thank you so in order for it to work you have to put the scale coding in after the sphere is set to true and then having the sphere set to false at the end to close it all off.
Well, before it was scaling up as soon as the game started, without regard for whether the buttons were held down So, I suppose if you waited some time, it would be scaled up entirely before you realized. =)
Also, 1 small note… the code, as-is, is locked more to the frame rate than you might want.
You could adjust it to use Time.deltaTime and some factor (combined) to get the scaling at a consistent time, instead… If you want.
Thanks so something similar to this “float translation = Time.deltaTime * 10” with the 10 being seconds? if so do i add it to the same line as the transform.localscale
When you multiply it by another number, it’s like saying “I want x amount in a second”. In your example, you’d be saying you want 10 in a second. So, you decide what value suits the speed you’d like. Just experiment and see
works and seems to run alot smoother aswell is it possible to add time limits to multiple scales? what i mean is, lets say i hold the triggers down and the sphere grows from .001 to 100 in 10 seconds and then pauses for a further 10 seconds and then add another scale value?
like .001-100 wait 10 seconds while still holding triggers then after 10 seconds it bumps from 100 to 200 and just keep repeating untill ive had enough
sounds odd but what i have in my head seems to be working smoothly
re: your other question…
Well, that would be totally different than you’re maximum value of 1 lol.
Of course it’s possible You’d have to write some code to start the pause you described when you reach your amount, and then check when that time is up, etc…
Just think through your idea and try to write it out. heh.