Question by
conecall1 · Nov 01, 2016 at 02:44 AM ·
movement script
Movement by tilting phone
Hello, atm i have more or less made a game, but i rather have it as a game on a phone instead of computer. for now the movement is left/right arrow keys and A/D. As this is the first game i have made in Unity, i kinda lack the skills to know everything, so i was hoping for some guidance, on how to make the script. Thanks for any help at all & merry christmas x). the script i have atm
using UnityEngine;
using System.Collections;
public class playerMovement : MonoBehaviour
{
private Rigidbody2D myRigidbody;
public GameObject player;
public float movementSpeed;
public float fallSpeed;
// Use this for initialization
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called 50 times per second
void FixedUpdate()
{
player = GameObject.FindGameObjectWithTag("player");
player.GetComponent<Rigidbody2D>().freezeRotation = true;
float horizontal = Input.GetAxis("Horizontal");
HandleMovement(horizontal);
myRigidbody.gravityScale = myRigidbody.gravityScale * fallSpeed;
}
private void HandleMovement(float horizontal)
{
myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y);
//myRigidbody.AddForce(new Vector2(0, jumpForce));
}
}
Comment