Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Kitiarafox · Apr 29, 2016 at 06:37 AM · c#collisiongameobject

Scripting trouble, Float on Collision/collision open gate

I am working on my first unity scene and I want to make an object float up when it is bumped into. I know how to write a script to make it float but not when its collided with. I also want to make a gate when opens when the avatar walks into it. I am fairly new at scripting and have been trying combine a collision code with my float but it isnt working. I know a code that will make it change colors upon collision but taking that to what I want with float is proving harder than I thought. Any suggestions or help would be greatly appreciated.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kitiarafox · Apr 30, 2016 at 01:08 AM

I have not tried that yet but found a code idea for the door dealing with triggers. Triggers are new for me. I had a brief video show collision changing objects color and making one thing rocket up and keep going up forever but I want to try a trigger float but not sure how to. Scripting is something new to me and I want to figure it out.

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 AlbinoStoic · Apr 30, 2016 at 01:12 AM

Basically instead of OnCollisionEnter you can use OnTriggerEnter

OnCollisionStay OnTriggerStay

etc.

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 Kitiarafox · Apr 30, 2016 at 02:01 AM 0
Share

I tried this code for the gate opening but on the page showing how to this it says pull door which is my gate into the gate/door spot on the script area of the button but it has no option like this site shows. Site: http://videogamedesign24.com/tutorial-opening-doors-using-buttons-triggers-in-unity/ Code:
using UnityEngine; using System.Collections;

public class Door : $$anonymous$$onoBehaviour { public Vector3 OpenPosition; private bool open;

 public IEnumerator OpenUp ()
 {
     if (!open)
     {
         while (transform.position != OpenPosition)
         {
             transform.position = Vector3.$$anonymous$$oveTowards(transform.position, OpenPosition, 0.25f);

             if (Vector3.Distance(transform.position, OpenPosition) <= 0.25f)
             {
                 transform.position = OpenPosition;
                 open = true;
             }
             yield return null;
         }
     }
 }

}

and

using UnityEngine; using System.Collections;

public class TriggerButton : $$anonymous$$onoBehaviour { public GameObject Door;

 void OnTriggerEnter (Collider collider)
 {
     if (collider.gameObject.tag == "Player")
         StartCoroutine(Door.GetComponent().OpenUp());
 }    

}

now as for the float trigger I am lost on how to write it. I am thinking i could do something lke the trigger above to rotate but my brain is missing the dots to connect them. I am just starting script codes. Forgive my lack of understanding, I am new to all this.

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 can i allow my character to jump if he has a powerup.,Changing a variable from one script to another 0 Answers

Detect overlapping objects 2D game 0 Answers

Why is my game object not being destroyed? 1 Answer

How do I get my character to collide with an object, he dies, and respawnee at the beginning of the map? 1 Answer

How to get parent with component on collision? 0 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