So I'm currently starting with programming, and I'm fresh to this topic.
I did start with the Unity game engine; people say it's not the best way to start but whatever.
I made the first game with the basic tutorial of unity.
Tho I can't yet really understand the complexity of C#. (Using Visual Studio, not sure if I should switch to sublime and how)
This game is about moving a ball around and collecting stuff. On the PC, it works just fine with the AddForce and Vector3 movement on the arrow keys. Though I wanted to try making this game for a mobile device, I thought about instead of typing the screen I might use the gyroscope of the mobile device. I found the "gyro" variable(?) in the Unity API documentation, but I don't really know how I define it just to move x and z-axis, so the ball won't starts flying off the table. I tried with the accelerator variable(?), but exactly this happened, even tho y-axis was set to 0. The following code is what i have at GameObject "player" so far:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class AccelerometerInput : MonoBehaviour
{
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
private void Update()
{
transform.Translate(Input.gyro.x, 0, -Input.gyro.z);
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Capsule"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 8)
{
winText.text = "You Win";
}
}
}
I'm new to all of this, especially coding, anything that helps me understand how the language is interpreted will be much appreciated! Thank you!