- Home /
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#
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
}
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 :)