// Update is called once per frame void Update() { if(Input.GetMouseButtonDown(0)) { RaycastHit hitResult; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitResult)) { if(!beginSet) { begin = hitResult.point + Vector3.up * 1; beginSet = true; } else { end = hitResult.point + Vector3.up * 1; beginSet = false; Quaternion rotation = Quaternion.LookRotation(Vector3.RotateTowards(Vector3.forward, (end - begin), Mathf.PI * 2, 1)); var thing = Instantiate(pPrefab1, begin, rotation); BulletTrailController c = thing.gameObject.GetComponent<BulletTrailController>(); if(c != null) { c.Init(begin, end); } } } } }
public void UpdateEntity(IEntity entity, EntityState es) { IEntity e = GetEntity(es.id); if (e != null) { // Update entity UpdateEntityPosRot(e, es.pos.GetValue(), Quaternion.Euler(es.rot.GetValue())); e.health = es.health; e.attackTarget = es.attackTarget; IUnit unit = e.gameObject.GetComponent <IUnit>(); if (unit != null) { // Update unit health e.gameObject.GetComponent <VehicleController>().HP = e.health; // Update attack target on vehicle logic IEntity attackTarget = GetEntity(e.attackTarget); if (attackTarget != null) { Debug.Log("found entity attack target " + attackTarget); IUnit targetUniit = attackTarget.gameObject.GetComponent <IUnit>(); if (targetUniit != null) { unit.SetAttackTarget(targetUniit); } if (es.shot) { // TODO REFACTOR THIS if (unit.GetGameObject().GetComponent <VehicleAI>().atkStyle == AttackStyle.FixedGun) { // IF SHOT THIS FRAME SPAWN SHOOTING VISUALS GameObject bullet = Instantiate(bulletPrefab1, e.gameObject.transform.position, Quaternion.identity); BulletTrailController btc = bullet.GetComponent <BulletTrailController>(); btc.Init(e.gameObject.transform.position, attackTarget.gameObject.transform.position); } if (unit.GetGameObject().GetComponent <VehicleAI>().atkStyle == AttackStyle.TurretGun) { // IF SHOT THIS FRAME SPAWN SHOOTING VISUALS GameObject bullet = Instantiate(bulletPrefab2, e.gameObject.transform.position, Quaternion.identity); BulletTrailController btc = bullet.GetComponent <BulletTrailController>(); btc.Init(e.gameObject.transform.position, attackTarget.gameObject.transform.position); } } } } } }