Quantcast
Channel: Questions in topic: "up"
Viewing all articles
Browse latest Browse all 104

About power-ups...

$
0
0
Okay, so... I've been trying to make a game where you are a comet. It's a platformer that doesn't use jumping. But I seem to be having trouble regarding the programing of power-ups. I need two power-ups (for now, anyways): Boosting (raising the speed of the player for a short period of time when he/she collides with a boost panel) and Invincibity (pretty self-explanatory). My code is as follows: using UnityEngine; using System.Collections; public class BallController : MonoBehaviour { public float speed; public float initialSpeed = 10; public float topSpeed = 40; private float middleSpeed = 15; private float direction; private Rigidbody2D rigby; public ParticleSystem part; public GameObject suiEyes; public GameObject closedEyes; // Use this for initialization void Start () { speed = initialSpeed; rigby = GetComponent(); //part.GetComponent(); part.enableEmission = false; suiEyes.SetActive(true); closedEyes.SetActive(false); } // Update is called once per frame void FixedUpdate () { direction = Input.GetAxis("Horizontal"); if (direction != 0) { if (speed < topSpeed) { speed += 0.1f; print("speed x:" + speed + " speed y: " + rigby.velocity.y); } if (speed > topSpeed) { speed = topSpeed; } rigby.AddForce(new Vector3(direction * speed, 0, 0)); } else { speed = initialSpeed; } if (rigby.velocity.x >= middleSpeed || rigby.velocity.y < -16 || rigby.velocity.x <= (middleSpeed*-1)) { part.enableEmission = true; suiEyes.SetActive(false); closedEyes.SetActive(true); } else if (rigby.velocity.x < initialSpeed + 1 || rigby.velocity.y == 0) { part.enableEmission = false; suiEyes.SetActive(true); closedEyes.SetActive(false); } } void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.tag == "Boost") { topSpeed = topSpeed + 100; } } }

Viewing all articles
Browse latest Browse all 104

Trending Articles