Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class WheelControls : MonoBehaviour {
- public float maxSpeed;
- public float acceleration;
- public float rotationAcceleration;
- private float horizontalVelocity;
- private Rigidbody2D thisRigidBody;
- private float direction;
- private GameObject rengas;
- void Start () {
- thisRigidBody = this.GetComponent<Rigidbody2D> ();
- }
- void Update () {
- direction = Input.GetAxis ("Horizontal");
- horizontalVelocity = System.Math.Abs (thisRigidBody.velocity.x);
- //kaksi tapaa kiihdyttää: AddForce ja AddTorque
- if (horizontalVelocity < maxSpeed) {
- // thisRigidBody.AddForce (new Vector2(direction, 0) * acceleration);
- thisRigidBody.AddTorque (-direction * rotationAcceleration);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment