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
0
Question by MegaStevenLP · Mar 30, 2013 at 10:43 AM · not-working

Multiple Trigger Script doenst works!

Im having 2 pressure plates, both needs to be activated to destroy a Door. Why arent my scripts working?

DestroyDoor.js

 #pragma strict
 var box1 : GameObject;
 var box2 : GameObject;
 var door : GameObject;
 var pressurePlateApressed : PressurePlateAScript;
 var pressurePlateBpressed : PressurePlateBScript;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 
 
 
 function Destroy () {
 if (pressurePlateApressed && pressurePlateBpressed){
 Destroy(door);
 }
 
 }
 


pressureplateascript (b is the same way)

 #pragma strict
 
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter( box ) {
     if (gameObject.name == "Box") {
         
         Debug.Log("A");
         pressurePlateApressed = true;
     }
 }    
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
0

Answer by Chronos-L · Mar 30, 2013 at 10:48 AM

It will not work because:

  • your second script will not compile

  • your Destroy function is not called at all

  • you will destroy the door if A and B is assign to the first script, whether or not they are pressed is irrelevent

    Script 1

    pragma strict

    var box1 : GameObject; var box2 : GameObject; var door : GameObject; var plateA: PressurePlate; var plateB: PressurePlate;

    function Start () {

    }

    function Update () { Destroy(); }

    function Destroy () { if ( plateA.pressed && plateB.pressed ){ Destroy(door); } }

    PressurePlate.js

    pragma strict

    var pressed : boolean;

    function OnTriggerEnter( other : Collider ) { if (other.gameObject.name == "Box") { pressed = true; } }

    Irrelevant, but still important

You should work harder on your programming skill if you are going to keep on doing this.


You have a pressureplateascript and a pressureplatebscript, and they have the same behaviour, then why not use the same script for both A and B?

If I have 8 bots in a death-match and each bots have a revolver and a rifle, does that mean I have to write 24 different scripts?


In your pressureplateascript, you have a pressurePlateApressed in the OnTriggerEnter(), but you never define it in the script. Your script will not compile.


You have a passable logic in your Destroy(), but you never call that function at all, of course it wouldn't work. Not using a function is almost equal to not writing one, just that the latter doesn't waste the programmer's time and effort.


It is better to be harsh to you right now, it will make you start learning on the basic; I did this so that you will not shoot yourself in the leg when you start to work on scripts that is much more complex.

Comment
Add comment · Show 5 · 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 MegaStevenLP · Mar 30, 2013 at 10:57 AM 0
Share

Now the Door opens if i only activate one Pressure Plate??

avatar image Chronos-L · Mar 30, 2013 at 11:03 AM 0
Share

no, you have to activate both A and B.

You do not need 2 scripts for the same behaviour. When you assign PressurePlate.js to A and B, they will create their own copy of the script. $$anonymous$$aking changes to A will not affect B.

All gameobject has a transform component, will changing the scale of gameobject affects another irrelevant gameobject? No, because one transform belongs to one gameobject, in the similar sense, one PressurePlate.js to belongs to one gameObject.

avatar image MegaStevenLP · Mar 30, 2013 at 11:15 AM 0
Share

Now the Door didnt open WTF EDIT; If i activate one Pressure Plate, the Door opens. Why I want that the door opens f i activae both PPs

avatar image Chronos-L · Mar 30, 2013 at 11:19 AM 0
Share

The current if-statement condition in my answer: plateA.pressed && plateB.pressed means the door will be destroyed when both A and B is activate.

If you need just 1 to be activated to destroy the door, then change to plateA.pressed || plateB.pressed .

avatar image Chronos-L · Mar 30, 2013 at 11:29 AM 0
Share

The condition plateA.pressed && plateB.pressed means that both of them need to be touched to Destroy(door). The logic have no problem.

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

11 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

Related Questions

Problem With Enemy AI 0 Answers

My monster only choose one Target 2 Answers

Make Deaths end game 1 Answer

Vehicle help 1 Answer

if statement error 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