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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Arikada · Aug 25, 2013 at 04:07 PM · objectstagsproperties

2 Different Objectproperties on the same Script

Hello, first sry for my bad English ;)

I have one Script for a Questsystem.. it reads from a MySQL Database QuestInformations and give it back.

So i have two Object (Questgiver and Questend) and booth had the same Script.

I want now to add add some different Values on the Objects.. like: Object1: questgiver = true Object2: questgiver = false

i tryed it with public bool questgiver. But it overwrite itsself..

then i tryed it with tags like:

 if(GameObject.FindWithTag("QuestGiver")){
 //give quest
 }

But it dont work too..

Maybe someone have a Idea to solve this..

Greetings from Germany P.s. its C#

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 aldonaletto · Aug 25, 2013 at 04:15 PM

Do you want the script to know which type of object it's attached to? You could set different tags to the objects, and verify it like this:

 if (tag=="QuestGiver"){
     // this is a QuestGiver
 }

Or you could define a public boolean like you already did:

 public bool questGiver = false;

and set it in the Inspector. If you had problems with the variable modifying itself, probably somewhere in the code you had a typo like this:

 if (questGiver=true){ // this is an assignment, not a equality test (==)

It should be just

 if (questGiver){

or

 if (questGiver==true){

Finally, you could test the object name:

 if (name == "QuestGiver"){
      // this is the QuestGiver object
 }
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
Wiki

Answer by Arikada · Aug 25, 2013 at 05:26 PM

Hello,

the best thing for me would be when its possible with the

 public bool questGiver = false;

and i assing a value on the ObjectInspector.. but this dont work.. (maybe becouse i have assingend the same script on another object)

so i have made it with tags.. the first object have the Tag "QuestGiver" and the other object have "QuestEnd".. Yeah i checked it 6 times..

but it dont work, i get always the part for the "QuestGiver" and not for the "QuestEnd" (check the else on line 53)... here some more code:

 using UnityEngine;
 using System.Collections;
 
 public class questing : MonoBehaviour {
     
 
     public static bool showDialog;// = false;
     bool quest;
     
     
         
         
     void OnGUI()
     {
         
         if(Network.peerType == NetworkPeerType.Client)
             {
             if(tag=="QuestGiver"){
             if (showDialog){            
                     
         if(quest == true){
                     
                     
         GUILayout.BeginArea(new Rect(10,80,200,200));
         GUILayout.Label(Menu.abbrechen_text);
     
         if (GUILayout.Button(Menu.abbrechen_annehmen)){
                         
                 quest=false;
                 showDialog=false;
             }
         if (GUILayout.Button(Menu.abbrechen_abbrechen)){
             quest=true;    
             showDialog=false;
             }
         GUILayout.EndArea();
             
         }else{
         
         GUILayout.BeginArea(new Rect(10,80,200,200));
         GUILayout.Label(Menu.annehmen_text);
             if (GUILayout.Button(Menu.annehmen_annehmen)){
         quest=true;
         showDialog=false;
         }
         if (GUILayout.Button(Menu.annehmen_spaeter)){
         quest=false;    
         showDialog=false;
         }
     GUILayout.EndArea();
     }
     }
     }else{
                 
 if(showDialog){
    if (quest==true){
    GUILayout.BeginArea(new Rect(10,80,200,200));
    GUILayout.Label(Menu.abgeben_text);
 
         if (GUILayout.Button(Menu.abgeben_annehmen))
                 {
         quest=false;
         showDialog=false;
         }
     if (GUILayout.Button(Menu.abgeben_abbrechen))
         {
     quest=true;    
     showDialog=false;
     }
      GUILayout.EndArea();
      }    
     }
    }
   }
  }    
 }

so i never come to the "else".. but i think when i realise it with "tags" i have another problem.. becouse i want to add more as just one properitie.. want to add questid for ex. too :)

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

16 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

Related Questions

Calling 2 objects into script for onCollisionEnter? 1 Answer

How to affect a group of objects. 1 Answer

Is it possible to edit description field of jpg when saving screenshot? 2 Answers

Shader - Change Tag based on Properties 1 Answer

Find objects by one tag or another. 3 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