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
-1
Question by thehiveissocial · Sep 05, 2018 at 10:03 PM · triggerbooleankeypressanother script

How to make my Power Button stop my Conveyor Belt

I have two scripts, one on the Button that's a trigger volume, and the other is the conveyor belt itself. The conveyor belt script is simple it reads,

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Belt : MonoBehaviour { public GameObject belt; public Transform endpoint; public float speed; public bool beltOn; void OnTriggerStay(Collider other) { if(beltOn) { other.transform.position = Vector3.MoveTowards(other.transform.position, endpoint.position, speed * Time.deltaTime); } } }

Then, the next script is the script attached to the trigger volume near the power button.

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Trigger : MonoBehaviour { //Boolean used to check if the player is in the trigger volume. private bool isHere = false; private GameObject conveyorbelt; public GameObject RedButton; public Light ButtonLight; private Renderer Button_Rend; public Material Red; public Material Green; void Start() { //Assign our private variable equal to the Button's Renderer component. Button_Rend = RedButton.GetComponent(); } //Start of a function to swap light to green. void GreenButton() { //Set intensity. ButtonLight.intensity = 4; //Set color. ButtonLight.color = Color.green; } //Start of a function to swap light to red. void ButtonRed() { //Set button material. Button_Rend.material = Red; //set intensity ButtonLight.intensity = 4; //set the color. ButtonLight.color = Color.red; } void OnTriggerEnter(Collider entity) { if(entity.tag == "Player") { //If a colliding object tagged as Player enters the Trigger volume, change the value of isHere to true. isHere = true; } } //Function called when an object exits the trigger volume. void OnTriggerExit(Collider entity) { //If the object that has exited the trigger volume has the Player tag. if(entity.tag == "Player") { //If a colliding object tagged as Player exits the Trigger, change the value of isHere back to false. isHere = false; } } }

Now that's my code I have thus far. I want a code that can be scripted inside the Trigger Volume script named "Trigger." I want the code to have a requirement of the player being inside the trigger volume, they press the key E, and if the button is red, then the conveyor will turn on. If all those requirements are met and the button is green then I want it to stop the conveyor belt. I can get the button color to change by key presses, but can't get the belt to stop. Sorry if my message isn't the clearest message to read, but I'm just having trouble and didn't know where else to ask for help.


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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Selecting animation to play based on boolean 1 Answer

Play fbx animation on trigger and keypress 0 Answers

Trigger when holding key 1 Answer

Boolean variable won't trigger in other script 1 Answer

Timer onTriggerEnter doesn't launch 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