Need help with managing my scripts..
Well... Its kinda hard to explain for me. But im trying to put all my sound into one script/Gameobject named sound. But my current issue is how can i make...
void OnTriggerEnter() or OnCollisionEnter()
Work with my gameobject "Ball" without my script being attached to it. ): I figured out how to get a int from other scripts, but this isnt so easy or is it? My code for the sound script
using UnityEngine;
using System.Collections;
public class Sound : MonoBehaviour {
public AudioClip impact;
public Collider ball; // Tried to drag the ball into her guessing was worth a shot (:
AudioSource audio;
void Start() {
audio = GetComponent<AudioSource>();
}
void Update() {
GameObject Goal = GameObject.Find ("Goal2"); //Getting a int from another class
Score scoreCheck = Goal.GetComponent<Score>();
if(scoreCheck.score == 2) {
audio.PlayOneShot (impact, 0.7F);
}
}
void OnCollisionEnter(Collision col) { //Current code im having a problem with
audio.PlayOneShot (impact, 0.7F);
}
}
Im just starting in learning so sorry if im not the best (:
Your answer
Follow this Question
Related Questions
Alternatives to OnTriggerEnter and onCollisionEnter 0 Answers
Killing enemy jumping on his head 2 Answers
Add a score whenever a riceball hits the floating platform 0 Answers
Triggers Colliding With Triggers Not Working? [Solved] 1 Answer
How can I make a collider that gives me stat up to stop giving me it? 0 Answers