• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SUDGaming · Feb 26, 2013 at 02:26 AM · instantiateprefabplayerai

What to set to make a Instantiated prefab a collider to trigger and event?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by liamcary · Feb 26, 2013 at 06:01 AM

Does the prefab already have a collider? If so you just need to mark the collider as a trigger. Then in a script on that same object you can use "OnTriggerEnter()", "OnTriggerStay()" and "OnTriggerExit()" for any functionality when something enters the trigger. If you want to add the collider to a particular instance of a prefab at run-time you can use the AddComponent function and set the collider as a trigger. E.g:

 class Example : MonoBehaviour
 {
 public GameObject prefab;
 void Awake()
 {
    SphereCollider sphere = prefab.AddComponent<SphereCollider>();
    sphere.isTrigger = true;
 }
 
 void OnTriggerEnter(Collider other)
 {
    // do something
 }

}

AddComponent function: http://docs.unity3d.com/Documentation/ScriptReference/GameObject.AddComponent.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to turn a spawned enemy ( AI ) target on player?/ Why are my Hierarchy object turn prefab then no longer hold the transform object? 1 Answer

Multiplayer prefab player fall through floor on instantiate 0 Answers

Instantiating random prefabs when the player passes through a trigger 1 Answer

Any ideas on a simple AI script that doesn't use any drag/drop variables 1 Answer

Problem when assigning a prefab 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges