Skip to content

Instantly share code, notes, and snippets.

@sabotai
Created October 14, 2016 21:09
Show Gist options
  • Save sabotai/70ba28f5f2c907f8b0d6d24bf8fac5f9 to your computer and use it in GitHub Desktop.
Save sabotai/70ba28f5f2c907f8b0d6d24bf8fac5f9 to your computer and use it in GitHub Desktop.
GD205 Week 6 F16
using UnityEngine;
using System.Collections;
public class Hangry : MonoBehaviour {
public GameObject fishPellet;
public float howHangry;
bool hungry;
public float sphereSize = 10f;
// Use this for initialization
void Start () {
hungry = true;
}
// Update is called once per frame
void Update () {
transform.LookAt (fishPellet.transform);
Vector3 destination = fishPellet.transform.position;
Debug.Log("Destination is ... " + fishPellet.transform.position);
Vector3 direction = Vector3.Normalize (destination - transform.position);
//Debug.Log ("direction of food: " + direction);
GetComponent<Rigidbody> ().AddForce (direction * howHangry);
}
void OnCollisionEnter(Collision col){
//what did we collide with?
Debug.Log("fishie hit ... " + col.gameObject);
if (col.gameObject == fishPellet) {
Debug.Log ("yes......");
Vector3 nearbyPosition = fishPellet.transform.position + Random.insideUnitSphere * sphereSize;
GameObject clone = Instantiate (fishPellet, nearbyPosition, Quaternion.identity) as GameObject;
GameObject temp = fishPellet;
Destroy (temp);
fishPellet = clone;
//hungry = false;
//GetComponent<Rigidbody> ().velocity = Vector3.zero;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment