- Home /
Random spawn of object on trigger
I need help with the following:
When player enters a certain area it triggers a spawn (could be random from a list) of a object.
Can someone help?
ok i have made a trigger that that currently does the following:
using UnityEngine;
using System.Collections;
public class trigger_1 : $$anonymous$$onoBehaviour {
void OnTriggerEnter(Collider player) {
Debug.Log("Hello");
}
}
When i move my player it now triggers the msg.
But i do not know how to get ir to spawn an object + play a sound. Also i want the object to be timed to only appear for x-seconds.
Can someone help me?
Answer by CHHOST · Oct 02, 2012 at 04:50 PM
ok i have made a trigger that that currently does the following:
using UnityEngine;
using System.Collections;
public class trigger_1 : MonoBehaviour {
void OnTriggerEnter(Collider player) {
Debug.Log("Hello");
}
}
When i move my player it now triggers the msg.
But i do not know how to get ir to spawn an object + play a sound. Also i want the object to be timed to only appear for x-seconds.
Can someone help me?
Hi There.
Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.
You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]
Please be patient if your question/reply doesn't show straight away.
As a new user, your posts and questions are held in a moderator que until it is approved and then it is displayed. When your karma rises, you'll be able to post questions, comments and answers without waiting for someone to approve it =]
Did you pay any attention to these comments? Not cool. You are attracting negative votes.
Don't post comments as answers , wait for your posts to be approved , do some tutorials as you are asking the most basic questions that are covered everywhere. If you bothered to look at :
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/
then all your questions here would be answered.
Play audio : http://www.unity3dstudent.com/2010/07/beginner-b10-audio-basics/
Destroy : http://www.unity3dstudent.com/2010/07/beginner-b04-destroying-objects/
I have given you alot of information, the rest is up to you , we are not here to write your scripts for you .....
Answer by CHHOST · Oct 02, 2012 at 05:30 PM
ok i have made a trigger that that currently does the following:
using UnityEngine;
using System.Collections;
public class trigger_1 : MonoBehaviour {
void OnTriggerEnter(Collider player) {
Debug.Log("Hello");
}
}
When i move my player it now triggers the msg.
But i do not know how to get ir to spawn an object + play a sound. Also i want the object to be timed to only appear for x-seconds.
Can someone help me?
Answer by AlucardJay · Oct 02, 2012 at 11:00 AM
Unity Scripting Reference has alot of information. Also, a search engine is your friend, especially for what you are asking.
These are the relevant Unity Scripting References for your question :
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html
some demonstration videos :
http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/
http://www.unity3dstudent.com/2010/07/beginner-b13-trigger-collision-detection/
http://www.unity3dstudent.com/2010/07/beginner-b05-instantiate-to-create-objects/
Here is a list of tutorials to get you going :
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/
this is the YouTube link for the above as one playlist : http://www.youtube.com/watch?v=-oXYHNSmTxg&list=PL27B696FB515608D2&feature=plcp
the Unity Wiki : http://wiki.unity3d.com/index.php/Tutorials
A list of resources : http://answers.unity3d.com/questions/12321/how-can-i-start-learning-unity-fast-list-of-tutori.html
ok i have made a trigger that that currently does the following:
using UnityEngine;
using System.Collections;
public class trigger_1 : $$anonymous$$onoBehaviour {
void OnTriggerEnter(Collider player) {
Debug.Log("Hello");
}
}
When i move my player it now triggers the msg.
But i do not know how to get ir to spawn an object + play a sound. Also i want the object to be timed to only appear for x-seconds.
Can someone help me?