- Home /
Need help combining code
Okay so basically I am making a script for Unity iPhone so whenever I touch the gameobject which is a soccer ball it bounces up. I have two scripts and I need to combine them. The first script makes it so whenever the ball is touched, particles come out. The second script is addforce.
Below are the two scripts
var particle : GameObject;
function Update () {
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
if (Physics.Raycast (ray)) {
// Create a particle if hit
Instantiate (particle, transform.position, transform.rotation);
}
}
}
}
The Second Script
function FixedUpdate () {
rigidbody.AddForce (Vector3.up * 10);
}
How would I replace the create particle with the addforce?
I'm not entirely sure what you are asking, but it seems to me that you want the soccer ball to jump when pressed. In that case just put it in the if statement (Note that i have not checked if the raycasting is correct, but if it is, the soccer ball should jump when tapped). I don't really see any use for the FixedUpdate() here. I also have no idea what you mean by "replace". If you wanted to replace just delete the particle code and do what i mentioned above.
Answer by Berenger · Jun 20, 2012 at 05:36 AM
I simplified it, but you'll get my point :
function Update()
{
if( input touch )
OnTouch();
}
function OnTouch(){
Instantiate particles;
yield WaitForFixedUpdate();
rigidbody.AddForce (Vector3.up * 10);
}
Im getting an error. It says " BCE0044: expecting ), found 'Touch' "