Hi guys, Im just starting my adventure with c# and unity so please forgive me my lack of knowledge and messy code. I was digging through the internet for 2 days , but nothing i found worked for me. What I need is how to get device position on void start, so every time i run game, game detects phone in 0 position.`
public class Controller : MonoBehaviour {
Rigidbody rb;
float dirX;
public float moveSpeed = 10f;
// Start
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update
void Update () {
dirX = Input.acceleration.x * moveSpeed;
//limit y-axis movement for future ramps etc
transform.position = new Vector3(transform.position.x, Mathf.Clamp (transform.position.y,-99f,20f), transform.position.z);
}
// FixedUpdate
void FixedUpdate()
{
rb.velocity = new Vector3 (0, -4f, dirX);
transform.position = new Vector3(transform.position.x - 0.2f, transform.position.y, transform.position.z);
}
}
I have tried This one how to detect device start position for player acceleration (iPhone) But it didn’t work for me neither(im working on android).
I will appreciate any advice and help.