Wrong phrasing

Hi guys,

i have a little problem with my Unity Script, that is writting in CSharp:

using UnityEngine;
using System.Collections;

public class Kegel : MonoBehaviour {
	public Vector3 startposition;

	// Use this for initialization
	void Start () {

		startposition = transform.position ; 


	
	}
	
	// Update is called once per frame
	void Update () {

		if(transform.position.y <= -10 )
			
			transform.position = startposition;
		
		rigidbody.angularVelocity = Vector3.zero;
		
		rigidbody.velocity = Vector3.zero;
		
		
		
		return;

		if(Input.GetKey(KeyCode.W ) )
	
		   rigidbody.AddTorque(20*Time.deltaTime,0,0);

		if(Input.GetKey(KeyCode.S))
			
			rigidbody.AddTorque(-20*Time.deltaTime,0,0);

		if(Input.GetKey(KeyCode.A))
			
			rigidbody.AddTorque(0,0,20*Time.deltaTime);


		if(Input.GetKey(KeyCode.D))
			
			rigidbody.AddTorque(0,0,-20*Time.deltaTime);

		if(Input.GetKeyDown(KeyCode.Space))

			rigidbody.AddForce (0,250,0);








	}
}

i want the sphere to go to the startposition but the problem is the following part:

}

// Update is called once per frame
	void Update () {

		if(transform.position.y <= -10 )
			
			transform.position = startposition;
		
		rigidbody.angularVelocity = Vector3.zero;
		
		rigidbody.velocity = Vector3.zero;
		
		
		
		return;

if I implement that, the sphere will no longer move. just down because of the physics but you can no longer influence the direction.
I have no clue, what the problem could be. I am just a beginner.

hi,

check this first (will be easier to read the code)
http://forum.unity3d.com/threads/134625-Using-code-tags-properly

you need some { } in there…

if(<condition>) 
statementA;
statementB;

statementA is governed by the if condition, statementB is going to be called regardless.

if(<condition>)
{
statementA;
statementB;
}

both statementA and statementB are governed by the if condition.

as a newbie I’d recommend using the {} for even single line if/condition usage just to get used to it and make it clear when you are reading what is controlled by the conditions… it doesn’t “cost” anything other than making the script a few characters bigger.

Thank you very much. It works!

I have another Question to you or the ones who read this:

How can I toggle a ParticleSystem on via a script. All tutorial explantions did not help me at all. As I mentioned, I am a very beginner. And I am from german and not that familiar with difficult formulations. I would really appreciate, if you could answer me that question