Skip to content

Instantly share code, notes, and snippets.

@walkies
Created June 5, 2018 05:09
Show Gist options
  • Save walkies/f5258ac3004ad8ae60167dbcd6188f60 to your computer and use it in GitHub Desktop.
Save walkies/f5258ac3004ad8ae60167dbcd6188f60 to your computer and use it in GitHub Desktop.
Ball revised
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