How to move a Gameobject in an Android Game with ScreenLandscape?
Hello everyone! I'm new to Unity. I'm creating a game for android where a cube do a route trying to dodge obstacles. My script has a problem: how can I do this withuout any problem? My script is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("d")) {
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
} else if (ScreenOrientation.LandscapeRight) {
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("a")) {
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
} else if (ScreenOrientation.LandscapeLeft) {
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
}
}
P.s My game is for pc too. Thanks in advice. Sorry for my english but i'm italian! :D
are you perhaps missing this?
void Awake ()
{
rb = GetComponent<RigidBody>();
}
what is the problem? at least I can't see any input code mobile related. if that's what's missing, please specify how you want to control.
Your answer
Follow this Question
Related Questions
why does my player move when anywhere on screen is touched? 1 Answer
animator and script issue 0 Answers
My 2d movement script isn't working 0 Answers
Diagonal movement is faster than horizontal or vertical, 2D top down, left click to move 1 Answer
Can't Figure Out How To Make A Line Tracking System 0 Answers