I found this script that I desperately want, unfortunately it written for another game engine, and I was hoping that someone could help me out with changing it. I tried but it’s not working.
https://opengameengine.codeplex.com/SourceControl/latest#ChopperGame/Chopper.cs
What I want is to make this: http://helicoptergame.net
So I could either change that, or make a whole new script, unfortunately I can’t right now.
you really shouldn’t ask people to write scripts for you but here’s a basic version of that script… you’ll want to play around with the values… and this version isn’t the best way to do things in unity, you should look into rigid body’s and applying force…
using UnityEngine;
using System.Collections;
public class Chopper : MonoBehaviour {
private float Acceleration = 0.4f;
private float MaxGravity = 1f;
private float MaxVelocity;
public bool Power;
private float Velocity;
// Use this for initialization
void Start () {
MaxGravity = -0.1f;
MaxVelocity = 0.4f;
Power = false;
Velocity = -1f;
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButton(0)) {
Power = true;
} else {
Power = false;
}
if(Power) {
Velocity += Acceleration * 0.6f;
if(Velocity < MaxVelocity) {
Velocity = MaxVelocity;
}
} else {
Velocity -= Acceleration;
if (Velocity > MaxGravity) {
Velocity = MaxGravity;
}
}
float newYPos = transform.position.y;
newYPos += Velocity;
transform.position = new Vector3(transform.position.x, newYPos, 0);
}
}