Hi,
How can i activate the animation or audio or any other when an android device is rotated to landscape left or landscape right, actually my idea is to move a car based on accelerometer so for that i need to activate the animation when moves fwd or bkwd.
Thanks!!!
Yes, you can do this.
Its easy. Try to find some information in the scripting reference about Input.acceleration or Input class in mainly.
I haven’t found exact Input method for this issue…could you pls guide me…
Thanks!!!
here you go, you can look under acceleration class.
you are welcome btw. 
Input.acceleration returns a Vector3 value each frame.
You can use this value to “Do Something” in your game.
Something like this can be used to calculate a force to apply to an object:
var shipPower : float;
function FixedUpdate () {
var acceleration : Vector3 = Input.acceleration;
var thrust : float = Mathf.Clamp (acceleration.y * shipPower, 0, 10)
rigidbody.AddRelativeForce (Vector3.up * thrust * Time.deltaTime, ForceMode.VelocityChange);
}
This way you can grab the value from the Input.acceleration and apply it to the rigidbody as a force.
You will need to poll your Input.acceleration for a value and apply it in your game to either trigger your animation or to drive your object.
since i am new to coding could you pls elaborate it…
Thanks!!!
First: If you need some help with the basics of coding, I have a few suggestions:
Between these two, you should get a basic handle on coding and the Unity API, just like we discussed in the Online Training Class.
Second: Can you go into more detail and describe what exactly you are trying to do? This will allow us to be more targeted and less generic about our suggestions.
Lastly: Remember from our Online Training Class: Variable hold values and Functions “Do things” to variables.
If you want to move a car based on key input, you would use something like:
Code taken from “Input.GetAxis”
var speed : float = 10.0;
function Update () {
// Get the vertical axis.
// By default they are mapped to the arrow keys.
// The value is in the range -1 to 1
var translation : float = Input.GetAxis ("Vertical") * speed;
// Make it move 10 meters per second instead of 10 meters per frame...
translation *= Time.deltaTime;
// Move translation along the object's z-axis
transform.Translate (0, 0, translation);
}
Now, with your mobile device, you seem to want to use the accelerometer to drive your object, not the keyboard. In this case, you want to use the values that come from the accelerometer rather than the keyboard:
var speed : float = 10.0;
function Update () {
// Get the accelerometer data:
var acceleration : Vector3 = Input.acceleration;
// Get the forward value from one of the three channels in the acceleration data:
var translation : float = acceleration.y * speed;
// Make it move 10 meters per second instead of 10 meters per frame...
translation *= Time.deltaTime;
// Move translation along the object's z-axis
transform.Translate (0, 0, translation);
}
This way, the value that you are using to move your object is coming from the accelerometer, rather than from the keyboard input.