- Home /
Photon instantiate (Assign Instantiated . get component
Ok I know you can do this with normal Instantiate and .getcomponent I was wondering if their was a way to do this with photon?
(trying to assign Instantiated objects target to the Same target that is instantiating the Object.) So my bombers, attack the ship my Carriers are Targeting. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CarrierBay : Photon.MonoBehaviour {
public int FighterCapacity = 3;
public int BomberCapacity = 2;
public int CurrentFighters = 0;
public int CurrentBomber = 0;
public bool IsOurs;
public bool SpawnFighters;
public bool SpawnBombers;
public CarrierAI CarrierScript;
public BomberAI BomberAISctipt;
public GameObject CarrierGameObject;
//----------------------------------------------------------------------------------------------------------------
void Start () {
CarrierScript = CarrierGameObject.GetComponent<CarrierAI> ();
SpawnFighters = true;
}
//----------------------------------------------------------------------------------------------------------------
// Update is called once per frame
void Update () {
//----------------------------------------------------------------------------------------------------------------
if (PhotonNetwork.isMasterClient == true) {
//----------------------------------------------------------------------------------------------------------------
if (CurrentFighters == FighterCapacity) {
SpawnFighters = false;
}
if (CurrentBomber == BomberCapacity) {
SpawnBombers = false;
}
if (SpawnFighters == true && IsOurs == true) {
CurrentFighters += 1;
PhotonView photonView = PhotonNetwork.Instantiate("T1Fighter",transform.position,transform.rotation,0);
BomberAISctipt = PhotonView.transform.gameObject.GetComponent<BomberAI> ();
BomberAISctipt.Target = Targeted;
}
if (SpawnBombers == true && IsOurs == true && CarrierScript.distance < 12200) {
CurrentFighters += 1;
PhotonView photonView = PhotonNetwork.Instantiate("T1bomber",transform.position,transform.rotation,0);
BomberAISctipt = PhotonView.transform.gameObject.GetComponent<BomberAI> ();
BomberAISctipt.Target = Targeted;
}
if (SpawnFighters == true && IsOurs == false) {
CurrentFighters += 1;
PhotonView photonView = PhotonNetwork.Instantiate("T2Fighter",transform.position,transform.rotation,0);
BomberAISctipt = PhotonView.transform.gameObject.GetComponent<BomberAI> ();
BomberAISctipt.Target = Targeted;
}
if (SpawnBombers == true && IsOurs == false && CarrierScript.distance < 12200) {
CurrentBomber += 1;
PhotonView photonView = PhotonNetwork.Instantiate("T2bomber",transform.position,transform.rotation,0);
BomberAISctipt = PhotonView.transform.gameObject.GetComponent<BomberAI> ();
BomberAISctipt.Target = Targeted;
}
}
}
//----------------------------------------------------------------------------------------------------------------
}
Answer by zak666 · Mar 15, 2017 at 11:28 AM
For anyone wondering Figured it out XD
if (SpawnBombers == true && IsOurs == true && CarrierScript.distance < 12200) {
CurrentFighters += 1;
GameObject Clone2;
Clone2 = PhotonNetwork.Instantiate("T1bomber",transform.position,transform.rotation,0);
BomberAISctipt = Clone2.GetComponent<BomberAI> ();
BomberAISctipt.Target = CarrierScript.Target;
}
Your answer
Follow this Question
Related Questions
Instantiated Prefab using its transform and object on other scripts 1 Answer
Photon Instantiate Prefab Script Problems 0 Answers
Limiting respawns on scene 1 Answer
PhotonNetwork.InstantiateSceneObject works in editor but not in build 2 Answers
Photon Instantiate Group's, Instantiating Prefabs that should already Exist 1 Answer