Created
June 5, 2018 05:09
-
-
Save walkies/f5258ac3004ad8ae60167dbcd6188f60 to your computer and use it in GitHub Desktop.
Ball revised
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Ball : MonoBehaviour | |
{ | |
public Countdown count; | |
public GameObject myPrefab; | |
public float thrust; | |
public Rigidbody rb; | |
void Start () | |
{ | |
rb = GetComponent<Rigidbody>(); | |
rb.AddForce(transform.forward * thrust); | |
} | |
void OnCollisionEnter(Collision c) | |
{ | |
if (c.gameObject.tag == "Paddle") | |
{ | |
Vector3 dir = c.contacts[0].point - transform.position; | |
dir = -dir.normalized; | |
rb.AddForce(dir * thrust * 2.5f); | |
} | |
else if (c.gameObject.tag == "Block") | |
{ | |
Vector3 dir = c.contacts[0].point - transform.position; | |
dir = -dir.normalized; | |
rb.AddForce(dir * thrust * 1.5f); | |
} | |
else if (c.gameObject.tag == "Floor") | |
{ | |
Instantiate(myPrefab, new Vector3(0, 3f, 2), Quaternion.Euler(0,180,0)); | |
count.currentTime--; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment