giving instantiated GameObjects some properties?
hey! i wanna give an instantiated GameObject a specific role. so so the first instantiated GameObject should be a defender, the second one a midfielder and so on.
for this, i have this stuff on my player script:
using UnityEngine;
using System.Collections;
public class Player_SSC : MonoBehaviour {
public bool goalie;
public bool defender;
public bool midfielder;
public bool forward;
public GameObject Manager;
public Transform postition;
void Update () {
if (goalie == true) {
Manager.GetComponent<ManagerScript>().target = postition;
}
}
}
but how do i set the bools based on the bools after i instantiate the player?
Looks like you're trying something that's too much for how good a programmer you are now. The line in Update -- that's the answer to your Q. How to have one script look over at another one.
But using several bools like that is a typical "I just learned program$$anonymous$$g" thing. Use just one variable to say the position. There are probably 20 other simple things you could learn with a small project, maybe reading generic C# program$$anonymous$$g books. I'd try a project using nothing that someone from the internet told you you had to use, like a manager or ... . Just using only program$$anonymous$$g stuff you understand.
Answer by Scheps · Sep 06, 2016 at 10:32 AM
My recommandation would be to use inheritance for your different roles.
Have a look at this well made Unity tutorial :
https://unity3d.com/learn/tutorials/topics/scripting/inheritance
I really recommand that because it will greatly simplify the evolution of your project, also it is a nice thing to learn.
If you want to stick with your current mechanism you can put an variable in your ManagerScript that you will increment each time your instantiante a new Player.
But don't do it, THIS IS BAD !
Let me know if you have questions.
thanks. i will have a look at the inheritance. at the moment its just for a quick prototype, so i think the "bad" way is okay for me at the moment :)
could you maybe explain the incrementing?