- Home /
Parent Buttons
I have gameobject buttons parented under a camera, my main player view. My camera should jump when one button, a gameobject, not a ui, is touched. It doesn't, however.
My script;
#pragma strict
private var JumpH = 8;
// Jump Hieght 8 units
private var IsFalling = false;
// Is not falling start
var particle : GameObject;
function Update ()
{
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
var ray = Camera.main.ScreenPointToRay (touch.position);
if (Physics.Raycast (ray)) {
//ad effects here
GetComponent.<Rigidbody>().velocity.y = JumpH;
IsFalling = true;
}
}
}
}
When I drag the script into camera, the script works as expected. (My camera and children jump when the ios screen is touched.) However, when I drag the script into one of the children (jump-key3), nothing happens. Tagging the button maincamera does nothing. If anyone could help, I would really appreciate it. I'm a newbie, so please don't get frustrated if I said anything dumb. Thanks!
no worries, this isnt stack overflow people totally understand when you say something dumb here. I do it all the time. Anyway i think your problem is that the button is a child of the camera. Usually, when i move game objects I do something like var height = 0; if (height < 8){ height += speed * Time.deltaTime; transform.position = new Vector3(transform.position.x, height, transform.position.z); . . and the above code would be called in update. This could also be a raycast issue, are you positive that the raycast is detecting the button?
Your answer
![](https://koobas.hobune.stream/wayback/20220611231924im_/https://answers.unity.com/themes/thub/images/avi.jpg)