Hi , please …
Hoe i can see a Monobehaviours class ??
Thank You at all …
Hi , please …
Hoe i can see a Monobehaviours class ??
Thank You at all …
If you want to see the Unity source codes, you better ask directly to the Unity Technologies team !!!
What exactly do you mean by “see them”?
the documentation to the class is in the script reference - MonoBehaviours
To make a class extending it you declare it as such
Apache :
Ciao !
Eri sarcastico vero ??
Finalmente qualche italiano nel forum !!!
Dreamora :
Thank you , i must try this , but maybe , i had in mind another idea but i think its better follow your idea …
Si ero sarcastico perchè non si capisce bene cosa intendi.
Spiegami bene cosa vorresti e vedrò se posso aiutarti.
It is not clear what you mean. If you want you can also explain better in italian and I’ll try to help you !!!
I think that you want say : What are the function in MonoBehaviour class?
If you use VS you can access to MonoBehaviour class, but only to see the declaretion methods and property.
If you want the source code, I think that you ask for a job to Unity developers.
eheh
Io voglio fare una classe in cui raccogliere tutti i miei script , cosi da dover solamente richiamarle in uno script attaccato ad un GameObject , nei miei script ho usato funzioni quali : instantiate , transform , vector3 etc , ed erano presenti le funzioni start() e update() .
Mentre creavo la classe mi sono accorto di questo e volevo vedere un esempio per trovare la strada giusta …
Grazie per l’ attenzione .
I want make a class for inglobe all my script , doing this i can call then with another script attached to a GameObject. I used functions such as: instant, transform, Vector3 etc, and there were functions start () and update ().
While I created the class I realized this and wanted to see an example to find the right way
thank You andrea !!! I try this !!! perhaps what I was looking !!
how i see this in VS ?
Is this of any help?
Guarda, non è ancora molto chiaro.
Se la tua intenzione è quella di creare una libreria comune per tutti gli oggetti presenti nel progetto allora la strada non è poi così difficile.
Se invece intendi rinchiudere tutto il tuo progetto in un unico script mi permetto di dirti che non sono d’accordo poichè distinguere gli oggetti in Unity come unità a se stanti è proprio la forza di questo motore grafico.
Mi spiego meglio: ogni script che estende Monobehaviour è appunto un Comportamento Singolo che va a definire un comportamento dell’oggetto a cui è attaccato. Ad esempio un Player avrà un comportamento che definisce l’ammontare della sua energia vitale e magari la funzione che la diminuisce nel momento in cui viene colpito.
Le funzioni Start, Update, ecc… messe a disposizione dal motore, identificano i momenti in cui i comportamenti vengono controllati ed eventualmente eseguiti.
Se tu andassi a mettere, per esempio, il controllo della salute del player e nella stessa funzione il controllo dei nemici che devono cercarti nel livello non è sbagliato ma è più confuso !! Se effettivamente dovessi poi dover ritoccare qualcosa sarebbe meglio poter avere degli enti a se capaci di autogestirsi e che potresti gestire meglio anche tu.
Scusa se mi sono dilungato. Comunque se volessi ulteriori chiarimenti fammi sapere e soprattutto fammi sapere quale delle soluzioni che ti ho proposto ti vanno meglio così da discuterne più in profondità.
Oh, un altra cosa: se nessuna delle mie ipotesi fosse ciò che vuoi fare allora spiegami meglio cosa intendi.
ENGLISH VERSION
It’s still not clear.
If you want to create a common library accessible to all of your Components it’s a simple way not too hard to do.
If you want to do a complete project in one script I’ll tell you that perhaps it is not a god idea because consider an object as a self one entity is the strong point of this engine.
The meaning of a MonoBehaviour is single behaviour of the object it is attached to.
The Start, Update, etc… functions, brought to you by the engine, define the moment in which this behaviour will be checked and executed.
If you will write all your behavious in a single script it’s not an error but it will be lot confused !! To have a single entity that is able to handle itself and the link with the others entities of the game is for sure better than mix all in one.
Sorry to make this so long. However if you need more info let me know what way you want to take.
And please, if noone of this is the one you want try to explain better what you need
Si , penso proprio che la prima opzione sia la più adatta , quella che si avvicina di più al mio scopo …
Quale sarebbe il metodo per portare a termine questo ?
Comunque complimenti per Dynematica !
Grazie mille !
ENGLISH
Yes , I think that the first choise is the better
How i can do this ?
Thank You very much !
Congratulation for the Dynematica Project .
Grazie per i complimenti !!!
Allora, per creare una libreria potresti semplicemente usare dei metodi statici (che però esulano dai componenti di Unity ed è semplicemente una questione di programmazione).
Ad esempio (banale ma rende l’idea) un metodo per diminuire la vita di giocatori e nemici sarebbe:
public static float applyDamage (float life, float damage) {
return life - damage;
} // applyDamage
Se invece hai bisogno di utilizzare variabili o metodi di Unity comuni allora potresti creare un gameobject a cui collegare il tuo script e poi dare i riferimenti via Inspector a tutti coloro che devono compiere le stesse azioni.
Esempio (sempre stupido e banale):
public class CommonClass: MonoBehaviour {
public Vector3 currentPlayerPosition;
public Transform player;
void Start () {
currentPlayerPosition = player.position;
} // Start
public void commonFunction () {
Debug.Log ("commonFunction executed");
} // commonFunction
} // CommonClass
e per usarla basta avere uno script fatto così:
public class Script: MonoBehaviour {
public CommonClass commonClass; // da collegare via inspector
private void Function () {
Debug.Log (commonClass.currentPlayerPosition);
commonClass.commonFunction ();
} // Function
} // Script
Semplice !!!
ENGLISH VERSION
Thanks about the compliments !!!
Well, to create a library you can simply use some static methods.
Here is a simple example: a method to apply damage to players and enemies:
public static float applyDamage (float life, float damage) {
return life - damage;
} // applyDamage
If you need to use variables or methods regarding Unity or not static then you can ceate a gameobject and attach to it the script with the common function.
A simple and useless example is:
public class CommonClass: MonoBehaviour {
public Vector3 currentPlayerPosition;
public Transform player;
void Start () {
currentPlayerPosition = player.position;
} // Start
public void commonFunction () {
Debug.Log ("commonFunction executed");
} // commonFunction
} // CommonClass
and to use that you need to have a script like this:
public class Script: MonoBehaviour {
public CommonClass commonClass; // to assign via inspector
private void Function () {
Debug.Log (commonClass.currentPlayerPosition);
commonClass.commonFunction ();
} // Function
} // Script
Simple !!!
Grazie sei un amico!
Ora vado a mangiare poi provo
Complimenti ancora…
In estate vado sempre a Praia a mare
Oggi pomeriggio provo questo metodo poi ti dico se ce l’ho fatta =D
You’re welcome !!!
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Text;
public class d1 : MonoBehaviour {
static GameObject enemy;
public int j=0;
public String[] oggetto = new String[];
public int k = 0;
public float[] pos = new float[];
public int index = 0;
public String filename ;
//----------------------------------------------------------------------------------------------------------------
void Start() {
oggetto = fileread("hero.txt");
pos = posread("posizione.txt");
int i = 0;
Debug.Log((oggetto.Length)-1);
while(oggetto.Length!=i+1){
Debug.Log(oggetto[i]);
enemy = Instantiate(UnityEngine.Resources.Load(oggetto[i]));
enemy.transform.localScale.z+=60;
enemy.transform.localScale.y+=50;
enemy.transform.localScale.x+=50;
enemy.transform.position = Vector3((pos[index]),(pos[index++]),(pos[index++]));
index++;
i++;
if(oggetto.Length==i)
break;
}
j=i;
}
//----------------------------------------------------------------------------------------------------------------
public String[] fileread (String filename) {
try {
int[] line ;
StreamReader sr = new StreamReader( Application.dataPath+"/"+filename);
int i = 0;
int p = 0;
while(p!=1){
line[i] = sr.ReadLine();
if(line[i]=="stop"){
p = 1;
line[i]=null;
}
// print(line[i]);
i++;
}
sr.Close();
sr = null;
return line;
}
catch (Exception e) {
Debug.Log("internal error!");
return null;
}
}
//----------------------------------------------------------------------------------------------------------------
public float[] posread (String filename) {
try {
float[] xyz ;
StreamReader dr = new StreamReader( Application.dataPath+"/"+filename);
int i = 0;
int p = 0;
while(p!=1){
xyz[i] = dr.ReadLine();
if(xyz[i]=="stop"){
p = 1;
xyz[i]=null;
}
// print(xyz[i]);
i++;
}
//Debug.Log(xyz[i]);
dr.Close();
dr = null;
return xyz;
}
catch (Exception e) {
Debug.Log("internal error!");
return null;
}
}
}
There are some error … where i wrong ?
enemy.transform.position = Vector3((pos[index]),(pos[index++]),(pos[index++]));
If I’m not wrong and if this is C# you need to write:
enemy.transform.position = [b]new[/b] Vector3((pos[index]),(pos[index++]),(pos[index++]));
However if you can also post the errors that Unity or VisualStudio gives to you it will be better to understand if there are others things wrong.
thank you apache , i add a console window
public String[] oggetto = new String[];
...
public float[] pos = new float[];
To instantiate an array you need to specify a initial dimension:
public String[] oggetto = new String[5];
...
public float[] pos = new float[5];
However if you will use a public array in the inspector you can set a dimension directly in the game object.
About the other error is because somewhere in your project (as I see not in the file you posted) you are calling a GUI function outside of the
void OnGUI () {
...
} // OnGUI
Unity standard method (as said in the error description).
Thank you very much again =)
sorry , but im dont know very well c# , i studing some guide but =/
I’ll answer to the new errors tomorrow !!!
thank you Apache , i see about this now …