Created
August 17, 2015 01:25
-
-
Save keiranlovett/d60d4db594dc31a30178 to your computer and use it in GitHub Desktop.
Unity: Stupid Simple Tron
This file contains hidden or 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 UnityEngine; | |
using System.Collections; | |
public class UnbreakableCollider : MonoBehaviour | |
{ | |
public Transform DotPrefab; | |
Vector3 lastDotPosition; | |
bool lastPointExists; | |
void Update() | |
{ | |
//testing script | |
/* lastPointExists = false; | |
MakeADot(new Vector3(10, 0, 0)); | |
MakeADot(new Vector3(5, 10, 0)); | |
MakeADot(new Vector3(7, 7, 7)); | |
MakeADot(new Vector3(0, 0, 0)); | |
MakeADot(new Vector3(0, 10, 10));*/ | |
MakeADot(this.transform.position); | |
} | |
void MakeADot(Vector3 newDotPosition) | |
{ | |
Transform dot =(Transform) Instantiate(DotPrefab, newDotPosition, Quaternion.identity); //use random identity to make dots looks more different | |
if (lastPointExists) | |
{ | |
GameObject colliderKeeper = new GameObject("collider"); | |
BoxCollider bc = colliderKeeper.AddComponent<BoxCollider>(); | |
colliderKeeper.transform.position = Vector3.Lerp(newDotPosition, lastDotPosition, 0.5f); | |
colliderKeeper.transform.LookAt(newDotPosition); | |
bc.size = new Vector3(1f, 0.1f, Vector3.Distance(newDotPosition, lastDotPosition)); | |
} | |
lastDotPosition = newDotPosition; | |
lastPointExists = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment