private void SpawnStatChangeText(ShipStats ship, int value, Sprite icon) { GameObject statChangeText = ship.GetComponent <ShipStatsUI>().statChangeText; GameObject instance = GameObject.Instantiate(statChangeText); RectTransform rect = instance.GetComponent <RectTransform>(); rect.anchoredPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); instance.transform.parent = ship.GetComponent <ShipStatsUI>().canvas; MoveAndFadeBehaviour moveAndFadeBehaviour = instance.GetComponent <MoveAndFadeBehaviour>(); moveAndFadeBehaviour.offset = new Vector2(0, +75); moveAndFadeBehaviour.SetValue(value, icon); }
public void SpawnStatChangeText(int value, Sprite icon = null) { ShipStatsUI shipStatsUI = shipStats.GetComponent <ShipStatsUI>(); GameObject statChangeUI = Instantiate(shipStatsUI.statChangeText); RectTransform rect = statChangeUI.GetComponent <RectTransform>(); Vector3 spawnPos = cam.WorldToScreenPoint(transform.GetChild(0).position); rect.anchoredPosition = new Vector2(spawnPos.x, spawnPos.y); statChangeUI.transform.parent = shipStats.GetComponent <ShipStatsUI>().canvas; // you have to set the parent after you change the anchored position or the position gets messed up. Don't set it in the instantiation. I don't know why someone decided to change that. MoveAndFadeBehaviour moveAndFadeBehaviour = statChangeUI.GetComponent <MoveAndFadeBehaviour>(); moveAndFadeBehaviour.offset = new Vector2(0, 25 + transform.GetChild(0).localPosition.y * 100); moveAndFadeBehaviour.SetValue(value, icon); }
void OnEnable() { SS = this.transform.parent.parent.GetComponent <ShipStats>(); BM = SS.GetComponent <BattleShipController>().BM; HUD.SetActive(true); Results.SetActive(false); Shown = false; RS.BM = BM; }
void FixedUpdate() { if (PlayerControlled) { if (CamEmpty == null) { CamEmpty = this.transform.GetChild(3).transform; } if (!SS.Dead) { PlayerControls(); } } else { if (Target == null) { if (!GameFinished) { FindTarget(); } } else { float TargetDist = Vector3.Distance(this.transform.position, Target.transform.position); //if(TargetDist > SearchRadius) //FindTarget(); if (ForwardGuns) { GunDirection = GunPos.forward; } else { float GunDist = Vector3.Distance(GunPos.position, Target.transform.position); GunDirection = (Target.transform.position - GunPos.position) / GunDist; } FaceTarget(); float SlowDist = ShipInfo.StopDistance + Target.GetComponent <BattleShipController>().ShipInfo.StopDistance; if (SS.Shields > 0f) { if (TargetDist > SlowDist) { MoveDirection = this.transform.forward; } else { if ((TargetDist / SlowDist) > 0.5f) { MoveDirection = this.transform.forward * (TargetDist / SlowDist); } else { MoveDirection = -this.transform.forward; } MoveDirection += this.transform.right * Random.Range(-1f, 1f); } } else { MoveDirection = -this.transform.forward; } MoveDirection += new Vector3(0f, Random.Range(-1f, 1f), 0f); Accelerate(); if (TargetDist < (ShipInfo.WeaponsRange + Target.GetComponent <BattleShipController>().ShipInfo.WeaponsRange)) { float ran = Random.Range(0f, 20f); if (ran < 1f) { Fire(); } } } } }