Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
-1
Question by Dmitri · Apr 20, 2012 at 04:04 PM · collisionobjects

More than 1 object in oncollisionenter

Hello guys!!! if some 1 know can i put in OncollisionEnter more that 1 object this is script:

function OnCollisionEnter(Gun : Collision){

  if (Gun.gameObject.tag == "gun")  {

  isparent=true;

  isPlayingSound=true;

  destroyaudiosource.Play();

  GunpositionTransform.parent=transform;    

  GunpositionTransform.localPosition = Vector3(-3.122956,-0.01368039,0.04606679);

  Update();
 }
 
 
 else {
 if (Gun.gameObject.tag == "mesh"){
     

} } }

and i wonna parent 2 more other object whith other position to parent if collision is detected. how can i do that if :

function OnCollisionEnter(gun:Collison || gun2:Collision)----->not work

Comment
Add comment · Show 3
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
avatar image Dmitri · Apr 20, 2012 at 05:24 PM 0
Share

i just won to know how can i add more then 1 object to OnCollisionEnter. i think for that its not needed the code but i will show he's big:

pragma strict

var destroy :AudioClip;

private var destroyaudiosource:AudioSource;

private var isPlayingSound:boolean;

var bullet: Transform;

var bulletspeed: float=5000;

var isparent:boolean;

private var placespawn: GameObject;

var GunpositionTransform=placespawn.transform;

function Start(){

 destroyaudiosource=gameObject.AddComponent(AudioSource);
 destroyaudiosource.clip=destroy;
 destroyaudiosource.loop=false;
 destroyaudiosource.volume=1.0;

}

function Update(){

if (Input.GetButtonDown("Fire1") && isparent==true){

var bulletCreate = Instantiate (bullet,GameObject.Find("spawnposition1").transform.position,Quaternion.identity);

     bulletCreate.rigidbody.AddForce(transform.forward * bulletspeed);
     }
 else {
     if (Input.GetButtonDown("Fire1") && isparent==false){
     Debug.Log("You Dont have any waypon! and that is your problem.");
 }
 }

}

function OnCollisionEnter(Gun3 : Collision){

  if (Gun3.gameObject.tag == "gun2")  {
  isparent=true;
  isPlayingSound=true;
  destroyaudiosource.Play();
  GunpositionTransform.parent=transform;    
  GunpositionTransform.localPosition = Vector3(-0.2782021,0.3591104,-5.368056);
  Update();
 }
 
 
 else {
 if (Gun3.gameObject.tag == "mesh"){
     

} else { isparent=false;

 }

} }

avatar image fafase · Apr 20, 2012 at 05:26 PM 0
Share

I think you got me wrong, I did not mean you need to fully post it, I meant you need to select code and press 101010 or ctrl+k to make it look like code. Did you check the answer anyway?

avatar image Dmitri · Apr 20, 2012 at 06:36 PM 0
Share

i'm not checked but i reading and i think this is not what i need, but thx you verry much anyway. I just put 3 script with OnCollisionEnter in 1 object :) its work fine

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fafase · Apr 20, 2012 at 04:09 PM

     function OnCollisionEnter(gun:Collision){
       if(other.gameObject.tag=="gun"||other.gameObject.tag=="mesh"){
         // Do the same to both
      }
    }

 function OnCollisionEnter(gun:Collision){
   if(other.gameObject.tag=="gun"){
     // Do something with gun
   }
   else if(other.gameObject.tag=="mesh"){
   // Do smg to mesh
   }
 }


Is that what you meant? Try to post properly, your code shows all messed up, it is hard to figure out what you already have and what you do wrong.

Comment
Add comment · Show 1 · 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
avatar image Dmitri · Apr 20, 2012 at 06:38 PM 0
Share

Resolve problem: I just put 3 script (because i need to detect 3 object) with OnCollisionEnter in 1 object :) and its work fine

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Collision point on surface? 1 Answer

Ragdollize kinematic rigidbodies 0 Answers

How to check if an object is colliding with another from another script ? 1 Answer

Make Objects to ricochet 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges