// Use this for initialization void Start() { playerTransform = GetComponent <Transform>(); weaponSettings.currentNumberOfClips = weaponSettings.ammoSettings.startingNumberOfClips; weaponSettings.currentNumberOfRounds = weaponSettings.ammoSettings.startingNumberOfRounds; Cursor.lockState = CursorLockMode.Locked; //This needs to be seperated into it's own function call so that new weapons can be picked up automatically, in case we choose to have multiple weapons. if (GetComponentInChildren <Gun>()) { gunReference = GetComponentInChildren <Gun>().gameObject; weaponSettings = GetComponentInChildren <Gun>().weaponSettings; //temp solution. I'd like to get this automated. weaponSettings.currentNumberOfClips = GetComponentInChildren <Gun>().weaponSettings.ammoSettings.startingNumberOfClips; weaponSettings.currentNumberOfRounds = GetComponentInChildren <Gun>().weaponSettings.ammoSettings.startingNumberOfRounds; Camera.main.transform.parent = gunReference.transform.parent; // There's a proper way to do this right? Unity isn't this retarded right? gunReference.transform.localPosition = gunLocalPosition = new Vector3(0.015f, -0.25f, 0.09f); } }
private void FireShot(GunSettings gunSettings) { var ray = shotRayProvider.GetShotRay(gunState.Data.IsAiming, camera); shooting.FireShot(gunSettings.ShotRange, ray); shooting.InitiateCooldown(gunSettings.ShotCooldown); }
void FromJsonToObjects(string json) { string[] objects = json.Split(objSeperators, System.StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < objects.Length; i++) { string[] objectParts = objects[i].Split('|'); string Type = objectParts[0]; string Name = objectParts[1]; string Description = objectParts[2]; string ImgUrl = objectParts[3]; string Object = objectParts[4]; print("Type: " + Type); print("Name: " + Name); print("Description: " + Description); print("ImgUrl: " + ImgUrl); print("objecet: " + Object); Sprite spriteFromUrl = GetSprite(ImgUrl, value => spriteFromUrl = value); switch (Type) { case "Gun": GunStats gunStats = JsonUtility.FromJson <GunStats>(Object); GunSettings gun = ScriptableObject.CreateInstance <GunSettings>(); gun.Fill(gunStats, Name, Description); gun.Sprite = spriteFromUrl; Data.Instance.AddGun(gun); break; case "Vest": VestStats vestStats = JsonUtility.FromJson <VestStats>(Object); VestSettings vest = ScriptableObject.CreateInstance <VestSettings>(); vest.Sprite = spriteFromUrl; vest.Fill(Name, Description, vestStats); Data.Instance.AddVest(vest); break; case "Knife": KnifeStats knifeStats = JsonUtility.FromJson <KnifeStats>(Object); KnifeSettings knife = ScriptableObject.CreateInstance <KnifeSettings>(); knife.Fill(knifeStats, Name, Description); knife.Sprite = spriteFromUrl; Data.Instance.AddKnife(knife); break; case "Grenade": GrenadeStats grenadeStats = JsonUtility.FromJson <GrenadeStats>(Object); GrenadeSettings grenade = ScriptableObject.CreateInstance <GrenadeSettings>(); grenade.Fill(grenadeStats, Name, Description); grenade.Sprite = spriteFromUrl; Data.Instance.AddGrenade(grenade); break; default: Debug.Log("Unrecognised item type"); break; } } itemsLoaded = true; }
public override void Select() { base.Select(); string Name = GetTitle().text; GunSettings settings = Data.Instance.GetGunSettings(Name); Manager.DescriptionLbl.text = settings.Description; }
public string ManufactureGun(string type) { GunSettings info = GetGunInfo(type); GunState gun = new GunState(type, currentAmmo: info.magazineSize); GunRegistry.Add(gun.Id, gun); Debug.Log($"Manufactured new gun {type} with id {gun.Id}"); return(gun.Id); }
private void FireShot(GunSettings gunSettings) { Transform tmp = null; var ray = shotRayProvider.GetShotRay(gunState.Data.IsAiming, camera); var info = shooting.FireShot(gunSettings.ShotRange, ray, out tmp); shooting.InitiateCooldown(gunSettings.ShotCooldown); shootingWriter.SendShotsEvent(info); }
bool EnemyInRange(Transform enemy, GunSettings gun) { if (Vector3.Distance(enemy.position, transform.position) > gun.attackRangeMin && Vector3.Distance(enemy.position, transform.position) < gun.attackRangeMax) { return(true); } else { return(false); } }
bool withinRange(GunSettings gun, TroopActor troop) { if (Vector3.Distance(troop.transform.position, transform.position) > gun.attackRangeMin && Vector3.Distance(troop.transform.position, transform.position) < gun.attackRangeMax) { return(true); } else { return(false); } }
public void SetBulletVars(string type, string bulletId, string playerId, PlayerGunControl gunControl) { _gunControl = gunControl; GunSettings gunInfo = GunLocker.singleton.GetGunInfo(type); BulletId = bulletId; PlayerId = playerId; damage = gunInfo.damage; gameObject.name = bulletId; bulletSpeed = gunInfo.bulletSpeed; physicsHitMultiplier = gunInfo.physicsHitMultiplier; }
public override void Fill(ScriptableObject obj) { GunSettings settings = obj as GunSettings; GetTitle().text = settings.Name; GetPrice().text = settings.gunStats.Price.ToString(); Image img = GetImage(); Debug.Log(settings.Name + " " + (settings.Sprite == null)); img.sprite = settings.Sprite; Manager.DescriptionLbl.text = settings.Description; }
void Fire(GunSettings gun) { gun.onShoot.Invoke(); if (EnemyInSights(gun) && CanHitTarget(gun.attackTarget)) { if (gun.attackTarget.currentHealth - gun.damage <= 0) { gun.onKillShot.Invoke(); } gun.attackTarget.TakeDamage(gun.damage); } }
TroopActor ClosestEnemy(GunSettings gun) { float dis = 0f; TroopActor closestEnemy = null; foreach (TroopActor ta in op.allTroopActors) { if (ta.rankState != RankState.dead && IsAttackableUnit(ta)) { if ((dis == 0f || Vector3.Distance(ta.transform.position, transform.position) < dis) && EnemyInRange(ta.transform, gun) && ta != this && ta.team != team) { dis = Vector3.Distance(ta.transform.position, transform.position); closestEnemy = ta; } } } return(closestEnemy); }
bool EnemyInSights(GunSettings gun) { RaycastHit hit; if (Physics.Raycast(transform.position, (gun.attackTarget.transform.position - transform.position), out hit, Vector3.Distance(transform.position, gun.attackTarget.transform.position))) { if (hit.transform != gun.attackTarget.transform) { return(false); } else { return(true); } } else { return(true); } }
void ResetGunTimer(GunSettings gun) { gun.m_gunTimer = Random.Range((gun.TimeBetweenShots - (gun.TimeBetweenShots * gun.m_gunTimerRandomiser)), (gun.TimeBetweenShots + (gun.TimeBetweenShots * gun.m_gunTimerRandomiser))); }
public void AddGun(GunSettings settings) { AddToArray(ref Guns, settings); }
private void UpdateGun(GunLocker.GunState gun) { Debug.Log($"Updating gun to {gun.Id} for player {_networkManager.PlayerId}"); currentGun = gun; currentGunSetting = GunLocker.singleton.GetGunInfo(gun.Type); }