Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
0
Question by GoldBARR93 · Aug 11, 2015 at 01:25 AM · collisionobjectcolliderise

how to make a script when an object collides with an object it makes another object rise

I'm trying to make it so when I shoot a target the target is destroyed and I have a blocker raise up to unlock a separate area. I can't get it to make the other object rise, but I have the target disappear. This is what I have so far:

void OnCollisionEnter(Collision theCollision){

     if (theCollision.gameObject) {
         Destroy (gameObject);
         RaiseBlocker();
     }
 }

 void RaiseBlocker(){
     curMoveProportion += (Time.deltaTime / moveTime);
     if(curMoveProportion >= 1){
         if(targetPos == targetPos1){
             targetPos = targetPos2;
         } else {
             targetPos = targetPos1;
         }
         prevPos = transform.position;
         curMoveProportion = 0;
     }
     transform.position = Vector3.Lerp(prevPos, targetPos, curMoveProportion);
 }
Comment
Add comment · Show 4
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 allenallenallen · Aug 11, 2015 at 01:27 AM 0
Share

I'm confused as to which object this script is attached to. Because it looks you're moving transform.position which means this is the blocker. But then you also have the OnCollisionEnter which means this can be what you shot.

avatar image GoldBARR93 · Aug 11, 2015 at 04:40 AM 0
Share

This script is attached to the target. I was trying to make it so when the target was hit it would call the RaiseBlocker method to unlock a 2nd part of the course. I wasn't sure if I had to make a completely different RaiseBlocker script and have this one call the RaiseBlocker script. If so I wasn't sure how to do that.

avatar image allenallenallen · Aug 11, 2015 at 03:22 PM 1
Share

@GoldBARR93

There's a comment system. Please use it ins$$anonymous$$d of making a new answer. Converted to comment.

avatar image allenallenallen · Aug 11, 2015 at 03:25 PM 0
Share

It's easier to call another script than to deal with it on this one script that's about to get destroyed after collision.

And please, learn to search:

http://answers.unity3d.com/questions/7555/how-do-i-call-a-function-in-another-gameobjects-sc.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GiyomuGames · Aug 11, 2015 at 05:08 AM

agoallenallenallen is right, your code is strange. The script on the target should hold a reference of the object to raise. Then when your target is shot you tell the object-to-raise...to raise.

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
avatar image
0

Answer by B19g_A5s_B411s · Aug 11, 2015 at 03:21 PM

Destroy(gameObject) should be after RaiseBlocker. Functions execute the script in order.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make a script when u collide with an object it disappears 3 Answers

collision with objects, physics 1 Answer

Objects Touching? 1 Answer

How can I make a sound deploy after colliding with a certain object (or terrain)? 1 Answer

Collision between objects 2 Answers


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