i want to set maximum speed. What is my fault ? My English very very bad, sorry…
using UnityEngine;
using System.Collections;
public class platetet : MonoBehaviour {
//Movement Speed
public float speed = 2;
//Body Max Speed
public float maxSpeed = 50f;
//Flap Force
public float force = 100;
//JetpackForce
public float jetpackForce = 50;
// Use this for initialization
void Start () {
//Hareket edeceği yer
GetComponent<Rigidbody2D> ().velocity = Vector2.up * speed;
}
// Update is called once per frame
void Update ()
{
//Flap
if (Input.GetKeyDown (KeyCode.Space)) {
GetComponent<Rigidbody2D> ().AddForce (Vector2.up * force);
}
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch (i).phase == TouchPhase.Began)
GetComponent<Rigidbody2D> ().AddForce (Vector2.up * force);
foreach (Touch touch in Input.touches)
GetComponent<Rigidbody2D> ().AddForce (Vector2.up * jetpackForce);
if(GetComponent<Rigidbody2D>().velocity.magnitude > maxSpeed)
{
GetComponent<Rigidbody2D>().velocity = GetComponent<Rigidbody2D>().velocity.normalized * maxSpeed;
}
}
}
}