Question by
cyborg2020 · Nov 16, 2016 at 09:50 PM ·
movementmobilecontroller
controls 3 d ball for mobile
i want to contol my char(ball) in mobile but i dont know what to do this is my player code if anyone can give me a simple tuto for my code and ty. using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour { public float moveSpeed; public GameObject deathpaticles; private float maxspeed=5f; private Vector3 input;
private Vector3 spawn;
// Use this for initialization
void Start () {
spawn = transform.position;
}
// Update is called once per frame
void Update () {
input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0,Input.GetAxisRaw("Vertical"));
if(GetComponent<Rigidbody>().velocity.magnitude< maxspeed)
{
GetComponent<Rigidbody>().AddForce(input*(moveSpeed));
}
if (transform.position.y < -2) {
Die ();
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "enemy")
{
Die ();
}
}
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "goal")
{
GameManager.Completelevel();
}
}
void Die()
{
Instantiate (deathpaticles, transform.position, Quaternion.identity);
transform.position = spawn;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612100824im_/https://answers.unity.com/themes/thub/images/avi.jpg)