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 /
avatar image
0
Question by F35Lightning · Dec 08, 2015 at 03:50 AM · collision

Crafting collision Trigger not working

I apologize for the confusing title, but i seem to be having a problem with my code. The way its supposed to work ism when i enter the collider and press e its supposed to open up a crafting menu UI which it does not. I've checked whether or not its detecting the collisions but that dosent seem to be the problem. If any of you guys could perhaps tell me how to fix this issue i would be grateful. Also if you have any suggestions on how you guys want me to make the crafting system it would be also very much appreciated. Thanks!

The code: #pragma strict

 var CraftMenu : GameObject;
 var UIcanvas : GameObject;
 var ToggleWorkbench : int = 10;
 
 function Start () {
 
   ToggleWorkbench = 1;
   
 }
 
 function Update () {
 
 }
 
 function OnTriggerStay (col : Collider){
  
   if(Input.GetKey(KeyCode.E)){        
 
    switch(ToggleWorkbench){
     
      case 0:
        
        ToggleWorkbench = 1;
                       
        Time.timeScale = 0;    
      
        UIcanvas.active = false;
        CraftMenu.active = true;
       
      
      
      break;
      
      case 1:
        
        ToggleWorkbench = 2;
        
        Time.timeScale = 1;    
      
        UIcanvas.active = true;
        CraftMenu.active = false;
       
      
      
      break;   
  
    }
 
   }
 
 
 }
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
1

Answer by sandeepsmartest · Dec 08, 2015 at 06:45 AM

There are several ways to achieve this. Best way would be to check if the object is inside collider or not .For this make a identifier that becomes true when the object enters into collider you can get this by simply using OnTriggerStay. As soon as if player comes out of trigger zone make that identifier immediately false by simple using OnTriggerExit. Under update check if button is pressed and if identifier is true. By using these OnTriggerEnter,OnTriggerStay and OnTriggerExit you can check the collision state of the player Below given is very basic untested code written in c# this may be helpful you.

 public bool IsPlayerInTriggerZone;
 void Update()
     {
         if(IsPlayerInTriggerZone && Input.GetKey(KeyCode.C))
         {
             //do your stuff
         }
     }
     void OnTriggerEnter(Collider Col)
     {
         if(Col.gameObject.tag="")
         {
         print("Player just entered Trigger Zone");
         IsPlayerInTriggerZone = true;
         }
     }
     void OnTriggerStay(Collider Col)//Player Staying in trigger zone
     {
         if(Col.gameObject.tag=="TriggerZone")
         {
             print("Player Staying in trigger zone");
             IsPlayerInTriggerZone = true;
         }
         else
         {
             print("Player Staying NOT in trigger zone");
             IsPlayerInTriggerZone = true;
         }
     }
     void OnTriggerExit(Collider col2)//plyer just came out from trigger zone
     {
         print("plyer just came out from trigger zone");
        IsPlayerInTriggerZone = false;
     }

NSKS

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collision of a constantly moving object 0 Answers

Ignore Character Controller Collision 1 Answer

How to create a semi-passable barrier 1 Answer

NavMesh Collision Detection? 0 Answers

Collision detection for specific objects 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