Question by
mesutcankaptan · Aug 03, 2017 at 03:21 PM ·
scripting problemballstuckrestart game
I have a problem about my Arkanoid game. Please help!
Hey everybody! I made an arkanoid game, thanks to unity tutorials. But there is a one problem. I don't know what to do. Sometimes i throw the ball up, and it stuck horizontally. There is an example screenshot below. How can i restart level, if my ball stuck like this. I think i have to write a script like this: "When my ball stuck above some Y position, restart level" But how? There is my ball script in C#.. Can anyone help me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour {
public float ballInitialVelocity = 600f;
private Rigidbody rb;
private bool ballInPlay;
public ParticleSystem deadSplash;
// Use this for initialization
void Awake () {
rb = GetComponent<Rigidbody> ();
deadSplash.GetComponent<ParticleSystem> ().enableEmission = false;
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Space") && ballInPlay == false)
{
transform.parent = null;
ballInPlay = true;
rb.isKinematic = false;
rb.AddForce(new Vector3(ballInitialVelocity, ballInitialVelocity, 0));
}
}
void OnTriggerEnter (Collider col)
{
if (col.tag == "Water") {
deadSplash.GetComponent<ParticleSystem> ().enableEmission = true;
}
}
}
20170803151638-1.jpg
(372.6 kB)
Comment