I’m trying to create a code that, on collision of a RigidBody with a RigidBodySPSController, a sound occurs and the screen changes in some way (like a splash of red color or something along those lines to show that you’ve lost the game). I am unsure of how to incorporate new coding with what I already have.
The first part of the code is what I have and I’ve also included the coding I think I want to incorporate:
#pragma strict
public var target : Transform;
public var doFollow : boolean;
function Start () {
}
function Update () {
if(doFollow) {
// "interpolate" the distance from the ex to the player
transform.position = Vector3.Lerp(transform.position, target.position, .01);
}
}
.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
AudioSource audio;
void Start() {
audio = GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision collision) {
foreach (ContactPoint contact in collision.contacts) {
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
if (collision.relativeVelocity.magnitude > 2)
audio.Play();
}
}
If anyone knows how to help or to help me write out the code I would be forever grateful.