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;
}
}
}
//----------------------------------------------------------------------------------------------------------------
}