So I was trying to copy some code from a tutorial (if anyone has any good C# tutorials as well that would be nice). The tutorial I was following is here http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/top-down-2d and all the code can be seen at 19.10ish I followed the tutorial every step but my code doesn’t work, and I would also like to make it work on a touch screen so will it it need changing or will it just assume the place im touching on the screen is the mouse? Sorry I know this is a lot of questions but I have been trying for about 2 days now.
Here is my code im using:
I cant see anyway they are different,
using UnityEngine;
using System.Collections;
public class PlayerMobility : MonoBehaviour {
public float speed;
void FixedUpdate()
{
var mousePosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Quaternion rot = Quaternion.LookRotation (transform.position - mousePosition, Vector3.forward);
transform.rotation = rot;
transform.eulerAngles = new Vector3 (0, 0, transform.eulerAngles.z);
rigidbody2D.angularVelocity = 0;
float input = Input.GetAxis ("Vertical");
rigidbody2D.AddForce (gameObject.transform.up * speed * input);
}
}
it just seems to be the last little bit not working as the player rotates to the mouse correctly.