├── .gitattributes ├── img ├── preview_1.png ├── preview_2.png ├── preview_3.png └── codemap_white.png ├── .gitignore ├── Assets └── MainStuff │ └── Scripts │ ├── FadeAudioSource.cs │ ├── RotateObject.cs │ ├── Settings.cs │ ├── switchColor.cs │ ├── MoveMenuShips.cs │ ├── GrowAnimation.cs │ ├── CamControl.cs │ ├── Tower.cs │ ├── Fighter.cs │ ├── Building.cs │ ├── RollerEnemyBase.cs │ ├── MainMenu.cs │ ├── FactionIndex.cs │ ├── BombShell.cs │ ├── RocketShell.cs │ ├── Trooper.cs │ ├── Seeker.cs │ ├── GameMaster.cs │ ├── Follower.cs │ ├── Main.cs │ ├── Ship.cs │ ├── Weapon.cs │ └── Player.cs ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /img/preview_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfcoding/RTS-Sandbox/HEAD/img/preview_1.png -------------------------------------------------------------------------------- /img/preview_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfcoding/RTS-Sandbox/HEAD/img/preview_2.png -------------------------------------------------------------------------------- /img/preview_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfcoding/RTS-Sandbox/HEAD/img/preview_3.png -------------------------------------------------------------------------------- /img/codemap_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfcoding/RTS-Sandbox/HEAD/img/codemap_white.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Ignore everything in the root except the "Assets/MainStuff/Scripts" directory. 3 | /* 4 | !.gitignore 5 | 6 | !Assets/ 7 | Assets/* 8 | !Assets/MainStuff/ 9 | Assets/MainStuff/* 10 | !Assets/MainStuff/Scripts 11 | !img/ 12 | *.meta -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/FadeAudioSource.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public static class FadeAudioSource { 5 | 6 | public static IEnumerator FadeOut (AudioSource audioSource, float FadeTime) { 7 | float startVolume = audioSource.volume; 8 | 9 | while (audioSource.volume > 0) { 10 | audioSource.volume -= startVolume * Time.deltaTime / FadeTime; 11 | 12 | yield return null; 13 | } 14 | 15 | audioSource.Stop (); 16 | audioSource.volume = startVolume; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/RotateObject.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class RotateObject : MonoBehaviour 6 | { 7 | float x, y, z; 8 | float speed; 9 | public Rigidbody RD; 10 | Vector3 m_EulerAngleVelocity; 11 | float time; 12 | 13 | private void Awake() 14 | { 15 | speed = 0.5f; 16 | y = Random.Range(-speed, speed); 17 | } 18 | 19 | private void Start() 20 | { 21 | m_EulerAngleVelocity = new Vector3(0, 10, 0); 22 | } 23 | 24 | void FixedUpdate() 25 | { 26 | transform.RotateAround(new Vector3(0, 0, 0), Vector3.up, 10 * Time.deltaTime); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Settings.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | [RequireComponent(typeof(AudioSource))] 7 | 8 | public class Settings : MonoBehaviour 9 | { 10 | public static Settings SET; 11 | 12 | /// 13 | /// Count of base ships (including player) 14 | /// 15 | public int mainBaseCount; 16 | public int startMoney; 17 | public int unitsCount; 18 | public int attackProbability; 19 | public bool aiPlayerBase; 20 | 21 | void Awake() 22 | { 23 | if (SET != null) 24 | GameObject.Destroy(SET); 25 | else 26 | SET = this; 27 | 28 | DontDestroyOnLoad(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/switchColor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class switchColor : MonoBehaviour 6 | { 7 | 8 | public GameObject light; 9 | public bool triggered = true; 10 | int id; 11 | 12 | void Start() 13 | { 14 | id = gameObject.GetComponentInParent().factionId; 15 | InvokeRepeating("SwitchColor", 0f, 0.5f); 16 | } 17 | 18 | public void SwitchColor() 19 | { 20 | if (triggered) 21 | { 22 | light.gameObject.GetComponent().intensity = 10; 23 | light.gameObject.GetComponent().color = GameMaster.GM.fractionColors[id]; 24 | triggered = false; 25 | } 26 | else 27 | { 28 | light.gameObject.GetComponent().intensity = 0; 29 | triggered = true; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/MoveMenuShips.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class MoveMenuShips : MonoBehaviour 6 | { 7 | float timerY; 8 | float timerX; 9 | float timerZ; 10 | 11 | void Start() 12 | { 13 | timerX = Random.Range(0, 100); 14 | timerY = Random.Range(0, 100); 15 | timerZ = Random.Range(0, 100); 16 | } 17 | 18 | void FixedUpdate() 19 | { 20 | timerX += Time.deltaTime; 21 | timerY += Time.deltaTime; 22 | timerZ += Time.deltaTime; 23 | 24 | gameObject.transform.position = new Vector3(gameObject.transform.position.x + Mathf.Sin(timerX) * 0.15f, gameObject.transform.position.y + Mathf.Sin(timerY) * 0.15f, gameObject.transform.position.z + Mathf.Sin(timerZ) * 0.15f); 25 | gameObject.transform.RotateAround(new Vector3(0, 0, 0), Vector3.up, 6 * Time.deltaTime); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/GrowAnimation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class GrowAnimation : MonoBehaviour 6 | { 7 | public float tickBuilding; 8 | public float buildingHeightScale; 9 | public float buildSpeed; 10 | 11 | public void Start() 12 | { 13 | tickBuilding = 0.05f; 14 | InvokeRepeating("ConstructBuilding", 0f, 0.01f); 15 | } 16 | 17 | public void ConstructBuilding () 18 | { 19 | if (tickBuilding < buildingHeightScale) 20 | { 21 | gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, tickBuilding, gameObject.transform.localScale.z); 22 | tickBuilding += buildSpeed; 23 | } 24 | else if (tickBuilding > buildingHeightScale) 25 | { 26 | CancelInvoke("ConstructBuilding"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/CamControl.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class CamControl : MonoBehaviour 6 | { 7 | public float rotationSpeed; 8 | float mouseX, mouseY; 9 | public Transform lookObject; 10 | public Transform player; 11 | 12 | void Start() 13 | { 14 | rotationSpeed = 0.8f; 15 | } 16 | 17 | void LateUpdate() 18 | { 19 | Control(); 20 | } 21 | 22 | void Control () 23 | { 24 | transform.LookAt(lookObject); 25 | 26 | mouseX += Input.GetAxis("Mouse X") * rotationSpeed; 27 | mouseY += Input.GetAxis("Mouse Y") * rotationSpeed * (-1); 28 | mouseY = Mathf.Clamp(mouseY, -60, 60); 29 | 30 | if (player.GetComponent().spectatorMode == false) 31 | if (player.GetComponent().stopCamControls == false) 32 | player.rotation = Quaternion.Euler(mouseY, mouseX - 70, 0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Aleksander Fedotov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Tower.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | public class Tower : Seeker 7 | { 8 | public float healthBarTopPosition; 9 | public float levelTopPosition; 10 | 11 | public override void Awake() 12 | { 13 | level = 1; 14 | minDistance = 1000; 15 | minDistNum = 0; 16 | countOfItemsCollected = 0; 17 | alreadyHaveWeapon = true; 18 | dead = false; 19 | foundObject = false; 20 | 21 | textHP = Instantiate(GameMaster.GM.text3dDamage, transform.position + new Vector3(0, levelTopPosition, 0), Quaternion.Euler(0, 0, 0)); 22 | textHP.gameObject.GetComponent().text = level.ToString(); 23 | textHP.transform.parent = transform; 24 | 25 | healthBarScaleMultiplier = 0.3f; 26 | healthBar = Instantiate(GameMaster.GM.healthBar, transform.position + new Vector3(0, healthBarTopPosition, 0), Quaternion.Euler(0, 0, 0)); 27 | healthBar.transform.SetParent(gameObject.transform); 28 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.02f, 1); 29 | } 30 | 31 | public void Start() 32 | { 33 | 34 | } 35 | 36 | public override void FindItemsAround(List objectList, List platformList) 37 | { 38 | 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Fighter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Fighter : Trooper 6 | { 7 | float randomY; 8 | Rigidbody rb; 9 | 10 | public void Start() 11 | { 12 | timer = Random.Range(0, 100); 13 | health = 800; 14 | maxHP = 800; 15 | rb = gameObject.GetComponent(); 16 | 17 | randomCollisionStuckDirection = Random.Range(0, 2); 18 | 19 | if (randomCollisionStuckDirection == 0) 20 | randomCollisionStuckDirection = -1; 21 | if (randomCollisionStuckDirection == 1) 22 | randomCollisionStuckDirection = 1; 23 | } 24 | 25 | public override void Update() 26 | { 27 | FindItemsAround(GameMaster.GM.globalObjectList, GameMaster.GM.platformObjectList); 28 | 29 | if (dead == false) 30 | FlyAnimation(); 31 | else 32 | rb.useGravity = true; 33 | } 34 | 35 | public void FlyAnimation () 36 | { 37 | timer += Time.deltaTime; 38 | 39 | Vector3 moveSin = new Vector3(transform.position.x + Mathf.Sin(timer) * 0.1f, 40 | transform.position.y + Mathf.Sin(timer * 2f) * 0.1f, 41 | transform.position.z + Mathf.Sin(timer * 2f) * 0.1f); 42 | 43 | if (transform.position.y < 20) 44 | rb.AddForce(0, 300, 0, ForceMode.Impulse); 45 | 46 | rb.MovePosition(moveSin); 47 | } 48 | 49 | public override void OnCollisionStay(Collision collisioninfo) 50 | { 51 | if (collisioninfo.gameObject.GetComponent() != null || collisioninfo.gameObject.GetComponent() != null || collisioninfo.gameObject.GetComponent() != null) 52 | { 53 | gameObject.GetComponent().AddRelativeForce(new Vector3(100 * randomCollisionStuckDirection, 30, 0), ForceMode.Impulse); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Building.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Building : FactionIndex 6 | { 7 | public float tickBuilding; 8 | public float buildingHeightScale; 9 | public AudioSource beginConstruction; 10 | public AudioSource constructionComplete; 11 | public float buildSpeed; 12 | public Vector3 healthBarPosition; 13 | 14 | public override void Awake() 15 | { 16 | base.Awake(); 17 | } 18 | 19 | public void Start() 20 | { 21 | health = 5000; 22 | maxHP = 5000; 23 | tickBuilding = 0.05f; 24 | 25 | if (beginConstruction != null && factionId == 0 && GameMaster.GM.aiPlayerBase == false) 26 | beginConstruction.Play(); 27 | 28 | InvokeRepeating("ConstructBuilding", 0f, 0.05f); 29 | 30 | healthBarScaleMultiplier = 1; 31 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.05f, 1); 32 | healthBar.transform.localPosition = healthBarPosition; 33 | } 34 | 35 | public void FixedUpdate() 36 | { 37 | healthBar.transform.LookAt(Camera.main.transform.position); 38 | } 39 | 40 | public void ConstructBuilding() 41 | { 42 | if (tickBuilding < buildingHeightScale) 43 | { 44 | gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, tickBuilding, gameObject.transform.localScale.z); 45 | tickBuilding += buildSpeed; 46 | } 47 | else if (tickBuilding > buildingHeightScale) 48 | { 49 | healthBar.transform.localPosition += new Vector3(0, 4, 0); 50 | 51 | if (factionId == 0 && GameMaster.GM.aiPlayerBase == false) 52 | constructionComplete.Play(); 53 | 54 | CancelInvoke("ConstructBuilding"); 55 | } 56 | } 57 | 58 | public void OnCollisionEnter(Collision collisioninfo) 59 | { 60 | if (collisioninfo.gameObject.tag == "Barracs") 61 | { 62 | gameObject.transform.position = GameMaster.GM.shipObjectList[factionId].transform.position + new Vector3(Random.Range(-100, 100), -GameMaster.GM.shipObjectList[factionId].transform.position.y, Random.Range(-100, 100)); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTS-Sandbox 2 | C# Unity 3D classes for creation of action / real-time strategy games 3 | 4 | ## Game Example (Player vs AI vs AI) 5 | 6 | [![](img/preview_1.png?raw=true)](https://youtu.be/MSCK4LUibh0 "Game Example") 7 | 8 | ## 600 Units Battle (AI vs AI) 9 | 10 | [![](img/preview_2.png?raw=true)](https://youtu.be/4vnaKTg5Cvk "600 Units Test") 11 | 12 | ## Five Factions Battle (AI vs AI) 13 | 14 | [![](img/preview_3.png?raw=true)](https://youtu.be/AgjpS3nFU-U "Five Factions") 15 | 16 | ## Class Diagram 17 | 18 | ![](img/codemap_white.png) 19 | 20 | ## Features 21 | - Procedural creation of a randomized RTS battle with opposing factions interactions, simple economic system, building and resource mining 22 | - Two working modes: 23 | - Player vs AI 24 | - AI vs AI 25 | - All game logic code was created from scratch 26 | - Game example (videos above) uses free 3d-models, textures and some particle effects from Unity asset store 27 | 28 | ## Rules 29 | 30 | - "All against all" principle 31 | - A selected number of bases (Ship.cs) are placed on the map with physical resource objects (Follower.cs) at any place 32 | - Each faction has own unique color 33 | - AI opponents fight between their bases and the player (Player.cs) 34 | - Resource collector ships (Seeker.cs) of each faction ("factionId" in FactionIndex.cs) find resource objects and take to their bases 35 | - Resources change their colors to faction's color after the object picking up 36 | - AI builds defence towers and factories for units creation with collected resources 37 | - The player controls a small ship, attacks opponents and their bases 38 | - With a given probability, opponents send created units (Trooper.cs, Fighter.cs) to attack player's small ship and base 39 | - The player creates buildings (Building.cs), units, defence towers (Tower.cs), finds resources and takes to the base ship 40 | - The player groups units and gives them orders (follow the object, or attack the enemy) 41 | - Any unit, including the player, can pick up weapons: machine guns, rocket and bomb launchers (Weapon.cs) 42 | - Each unit has a level, which increases after destroying enemies 43 | - Resource is a physical rigidbody object that can be picked up as loot 44 | - All objects can be destroyable 45 | 46 | ## Usage 47 | 48 | - All needed prefabs are listed in GameMaster.cs 49 | - GameMaster.cs acts as a global static class that contains all prefab links for other classes 50 | - Add empty Game Object in Unity Hierarchy 51 | - Attach GameMaster.cs script to the object 52 | - Attach scripts for each prefab: 53 | - **Player:** Player.cs, PlayerController.cs, Main.cs 54 | - **Camera:** CamControl.cs 55 | - **Faction Base Ship:** Ship.cs 56 | - **Barracs and Factory:** Building.cs 57 | - **Gun-Tower, Rocket-Tower:** Tower.cs 58 | - **Trooper:** Trooper.cs 59 | - **LightShip:** Fighter.cs 60 | - **Resource Ship:** Seeker.cs 61 | - **Resource:** Follower.cs 62 | - **Machine Gun, Bomb Launcher, Rocket Launcher:** Weapon.cs 63 | - **Rocket:** RocketShell.cs 64 | - **Bomb:** BombShell.cs 65 | - Place player prefab with a Camera as a child on the map and connect all your other prefabs to GameMaster.cs 66 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/RollerEnemyBase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | public class RollerEnemyBase : Trooper 7 | { 8 | public override void Awake() 9 | { 10 | level = 1; 11 | attackTargetId = Random.Range(0, 6); 12 | targetIsShip = true; 13 | health = 2000; 14 | maxHP = 2000; 15 | destinationPass = false; 16 | foundTargetToAttack = false; 17 | wait = false; 18 | distToLerp = 170; 19 | gameObject.tag = "Trooper"; 20 | gameObject.name = "Roller"; 21 | wait = true; 22 | alreadyHaveWeapon = false; 23 | dead = false; 24 | foundObject = false; 25 | isVulnerable = true; 26 | textHP = Instantiate(GameMaster.GM.text3dDamage, transform.position + new Vector3(0, 10, 0), Quaternion.Euler(0, 0, 0)); 27 | textHP.gameObject.GetComponent().text = level.ToString(); 28 | textHP.transform.parent = transform; 29 | healthBarScaleMultiplier = 0.8f; 30 | pointFromShootingRandomize.Set(Random.Range(-40, 40), 0, Random.Range(-40, 40)); 31 | } 32 | 33 | public override void Update() 34 | { 35 | FindItemsAround(GameMaster.GM.globalObjectList, GameMaster.GM.platformObjectList); 36 | } 37 | 38 | public override void FindItemsAround(List _GlobalObjectList, List _PlatformList) 39 | { 40 | if (dead == false && stopDoing == false) 41 | { 42 | if (targetToChase != null) 43 | { 44 | if (targetToChase.GetComponent() != null) 45 | { 46 | pointFromShooting = targetToChase.transform.position - new Vector3(0, targetToChase.transform.position.y, 0); 47 | } 48 | else 49 | { 50 | pointFromShooting = targetToChase.transform.position; 51 | } 52 | } 53 | else 54 | { 55 | int rnDShip = Random.Range(0, GameMaster.GM.mainBaseCount); 56 | 57 | while (rnDShip == factionId) 58 | rnDShip = Random.Range(0, GameMaster.GM.mainBaseCount); 59 | 60 | if (factionId != 0 && GameMaster.GM.shipObjectList[rnDShip] != null) 61 | targetToChase = GameMaster.GM.shipObjectList[rnDShip]; 62 | else 63 | targetToChase = GameMaster.GM.player.gameObject; 64 | } 65 | 66 | if (targetToChase != null && targetToChase.GetComponent() != null) 67 | pointFromShooting = pointFromShooting + pointFromShootingRandomize * 4; 68 | 69 | if (targetToChase != null && targetToChase.GetComponent() == null) 70 | pointFromShooting = pointFromShooting + pointFromShootingRandomize; 71 | 72 | if ((currentWeapon != null && enemyToLook != null) || (currentWeapon != null && enemyToLook != null)) 73 | { 74 | if (enemyToLook.GetComponent() != null) 75 | { 76 | wait = true; 77 | } 78 | else if (enemyToLook.GetComponent() == null) 79 | { 80 | wait = true; 81 | } 82 | } 83 | else 84 | { 85 | wait = false; 86 | } 87 | 88 | // если враг мертв, то двигаться дальше 89 | if (enemyToLook != null && enemyToLook.GetComponent() != null && enemyToLook.GetComponent().dead == true && currentWeapon.GetComponent().playerFollowingCommand == true) 90 | wait = false; 91 | 92 | if (((Vector3.Distance(transform.position, pointFromShooting)) > 80) && (wait == false)) 93 | { 94 | Vector3 direction = (targetToChase.transform.position - transform.position).normalized; 95 | rbTrooper.AddForce(direction * 1, ForceMode.VelocityChange); 96 | } 97 | else 98 | { 99 | wait = true; 100 | } 101 | 102 | if (((Vector3.Distance(transform.position, pointFromShooting)) > 120)) 103 | { 104 | wait = false; 105 | } 106 | } 107 | 108 | // Анимация смерти 109 | if (dead == true && stopDoing == false) 110 | { 111 | stopDoing = true; 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/MainMenu.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using UnityEngine.SceneManagement; 6 | using TMPro; 7 | 8 | public class MainMenu : MonoBehaviour 9 | { 10 | public Slider factionsSlider; 11 | public Slider moneySlider; 12 | public Slider unitsSlider; 13 | public Slider probabilitySlider; 14 | public Toggle aiOnlyToggle; 15 | 16 | public TMP_Text factionCountText; 17 | public TMP_Text moneyCountText; 18 | public TMP_Text unitsCountText; 19 | public TMP_Text probabilityText; 20 | 21 | public GameObject factionShip; 22 | 23 | List shipsList; 24 | List factionColors; 25 | 26 | public void Start() 27 | { 28 | shipsList = new List(); 29 | SetBaseCount(); 30 | SetMoneyCount(); 31 | SetUnitsCount(); 32 | SetAttackProbability(); 33 | SetMode(); 34 | } 35 | 36 | public void PlayGame() 37 | { 38 | SceneManager.LoadScene(1, LoadSceneMode.Single); 39 | } 40 | 41 | public void QuitGame() 42 | { 43 | Application.Quit(); 44 | } 45 | 46 | public void SetBaseCount() 47 | { 48 | gameObject.GetComponent().Play(); 49 | 50 | int factionCount = (int)factionsSlider.value; 51 | Settings.SET.mainBaseCount = factionCount; 52 | 53 | factionCountText.GetComponent().text = $"Factions: {factionCount.ToString()}"; 54 | 55 | float spawnCircleAngle = Random.Range(0, 360); 56 | 57 | if (shipsList != null) 58 | { 59 | for (int i = 0; i < shipsList.Count; i++) 60 | { 61 | Destroy(shipsList[i].gameObject); 62 | } 63 | } 64 | 65 | factionColors = new List(); 66 | 67 | for (int i = 0; i < factionCount; i++) 68 | { 69 | float r, g, b; 70 | 71 | r = (float)(Random.Range(0, 255) / 255f); 72 | g = (float)(Random.Range(0, 255) / 255f); 73 | b = (float)(Random.Range(0, 255) / 255f); 74 | 75 | Color newRandomColor = new Color(r, g, b, 1f); 76 | factionColors.Add(newRandomColor); 77 | } 78 | 79 | factionColors[0] = new Color(0, 1, 1, 1f); 80 | factionColors[1] = new Color(1, 0, 1, 1f); 81 | 82 | for (int i = 0; i < factionCount; i++) 83 | { 84 | GameObject newShipObject = Instantiate(factionShip, new Vector3(200 * Mathf.Cos(spawnCircleAngle * 3.14f / 180), 0, 200 * Mathf.Sin(spawnCircleAngle * 3.14f / 180)), Quaternion.Euler(0, 0, 0)); 85 | newShipObject.transform.LookAt(new Vector3(0, 0, 0)); 86 | newShipObject.transform.localScale = new Vector3(0.045f, 0.045f, 0.045f); 87 | 88 | int lightsCount = 0; 89 | 90 | if (newShipObject.gameObject.GetComponentsInChildren() != null) 91 | { 92 | lightsCount = newShipObject.gameObject.GetComponentsInChildren().Length; 93 | 94 | for (int j = 0; j < lightsCount; j++) 95 | { 96 | newShipObject.gameObject.GetComponentsInChildren()[j].color = factionColors[i]; 97 | } 98 | } 99 | 100 | shipsList.Add(newShipObject); 101 | spawnCircleAngle += 360 / Settings.SET.mainBaseCount; 102 | } 103 | } 104 | 105 | public void SetMoneyCount() 106 | { 107 | int startMoney = (int)moneySlider.value; 108 | Settings.SET.startMoney = startMoney; 109 | moneyCountText.GetComponent().text = $"Start Money: {startMoney.ToString()} %"; 110 | } 111 | 112 | public void SetUnitsCount() 113 | { 114 | int maxUnits = (int)unitsSlider.value; 115 | Settings.SET.unitsCount = maxUnits; 116 | unitsCountText.GetComponent().text = $"Max Faction Units: {maxUnits.ToString()}"; 117 | } 118 | 119 | public void SetAttackProbability() 120 | { 121 | int attackProbability = (int)probabilitySlider.value; 122 | Settings.SET.attackProbability = attackProbability; 123 | probabilityText.GetComponent().text = $"AI Attack Probability: {attackProbability.ToString()} %"; 124 | } 125 | 126 | public void SetMode() 127 | { 128 | bool aiControlledPlayerBase = aiOnlyToggle.isOn; 129 | Settings.SET.aiPlayerBase = aiControlledPlayerBase; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/FactionIndex.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class FactionIndex : MonoBehaviour 6 | { 7 | public int factionId; 8 | 9 | public bool isSimpleFollower; 10 | public bool dead, totallyDead; 11 | public bool isVulnerable; 12 | public bool lootAfterDeath; 13 | 14 | public float health; 15 | public float maxHP; 16 | public float healthBarScaleMultiplier; 17 | public float level; 18 | 19 | public GameObject healthBar; 20 | public GameObject whoIsDamaging; 21 | public GameObject deathEffect; 22 | 23 | public AudioSource deathSound; 24 | 25 | public float healthBarHeight; 26 | public float textHpHeight; 27 | 28 | public virtual void Awake() 29 | { 30 | level = 1; 31 | health = 150; 32 | maxHP = 150; 33 | healthBarScaleMultiplier = 0; 34 | healthBar = Instantiate(GameMaster.GM.healthBar, transform.position + new Vector3(0, healthBarHeight, 0), Quaternion.Euler(0, 0, 0)); 35 | healthBar.transform.SetParent(gameObject.transform); 36 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.02f, 1); 37 | } 38 | 39 | public void SetFractionId(int fractionId) 40 | { 41 | this.factionId = fractionId; 42 | 43 | if (gameObject.name == "Seeker" || gameObject.name == "GunTower" || gameObject.name == "Tower") 44 | { 45 | int lightsCount = 0; 46 | 47 | if (gameObject.GetComponentsInChildren() != null) 48 | { 49 | lightsCount = gameObject.GetComponentsInChildren().Length; 50 | 51 | for (int i = 0; i < lightsCount; i++) 52 | { 53 | gameObject.GetComponentsInChildren()[i].color = GameMaster.GM.fractionColors[this.factionId]; 54 | } 55 | } 56 | } 57 | 58 | if (healthBar != null) 59 | healthBar.GetComponent().color = GameMaster.GM.fractionColors[this.factionId]; 60 | } 61 | 62 | public void SetHealth (float healthToSet) 63 | { 64 | health = healthToSet; 65 | maxHP = healthToSet; 66 | } 67 | 68 | public virtual void TakeDamage(float damage) 69 | { 70 | if (isVulnerable == true) 71 | { 72 | if (health > damage) 73 | { 74 | health -= damage; 75 | if (healthBar != null) 76 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.05f, 1); 77 | } 78 | else 79 | { 80 | if (dead == false) 81 | { 82 | if (healthBar != null) 83 | healthBar.transform.localScale = new Vector3(0, 0, 0); 84 | 85 | //DeathEffect = Instantiate(GameMaster.GM.SmokeAfterDeath, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 86 | //DeathEffect.transform.parent = gameObject.transform; 87 | 88 | if (deathEffect != null) 89 | { 90 | GameObject deadBoom = Instantiate(deathEffect, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 91 | Destroy(deadBoom, 5f); 92 | } 93 | 94 | if (deathSound != null) 95 | deathSound.Play(); 96 | 97 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 35); 98 | 99 | foreach (Collider hit in colliders) 100 | { 101 | if ((hit.GetComponent() != null && hit.GetComponent() == null && hit.GetComponent() == null) && (hit.name != "Rocket") && (hit.name != "Bomb")) 102 | hit.GetComponent().AddExplosionForce(700, gameObject.transform.position + new Vector3(0, 0, 0), 10, 1, ForceMode.Impulse); 103 | } 104 | 105 | if (lootAfterDeath == true) 106 | { 107 | for (int i = 0; i < 5; i++) 108 | { 109 | int RndNum = Random.Range(0, GameMaster.GM.detailsList.Count); 110 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.detailsList[RndNum], transform.position + new Vector3(Random.Range(0, 4), Random.Range(0, 4), Random.Range(0, 4)), Quaternion.Euler(0, 0, 0), "Follower", GameMaster.GM.globalObjectList); 111 | if (createdObject.GetComponent() == null) 112 | createdObject.AddComponent(); 113 | createdObject.GetComponent().mass = 5; 114 | if (createdObject.GetComponent() != null && createdObject.GetComponent().convex == false) 115 | createdObject.GetComponent().convex = true; 116 | } 117 | } 118 | } 119 | 120 | dead = true; 121 | health -= damage; 122 | GameMaster.GM.RecursiveDestroy(transform, gameObject, 5); 123 | } 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/BombShell.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class BombShell : RocketShell 6 | { 7 | bool exploded; 8 | public override void Awake() 9 | { 10 | isProjectile = true; 11 | playersBullet = false; 12 | 13 | if (gameObject.GetComponent() != null) 14 | { 15 | gameObject.GetComponent().AddRelativeForce(Random.Range(0, 200), Random.Range(0, 10), 1500, ForceMode.Impulse); 16 | gameObject.GetComponent().AddRelativeForce(0, 0, 0, ForceMode.Impulse); 17 | } 18 | } 19 | public override void MoveBullet() 20 | { 21 | Timer += Time.deltaTime; 22 | 23 | if (playersBullet == true && isHoming == true) 24 | if (Physics.BoxCast(GameMaster.GM.player.transform.TransformPoint(0, 0, 0), new Vector3(20, 20, 2), transform.forward, out RaycastHit hitInfo2, Quaternion.Euler(0, 0, 0), 400, 1 << 8)) 25 | if ((hitInfo2.transform.tag == "Seeker" || hitInfo2.transform.tag == "Trooper") && (hitInfo2.transform.GetComponent().factionId != 0)) 26 | { 27 | gameObject.transform.LookAt(hitInfo2.transform.position + new Vector3(0, 1, 0)); 28 | Vector3 normalizeDirection = (hitInfo2.transform.position + new Vector3(0, 1, 0) - gameObject.transform.position).normalized; 29 | gameObject.transform.position += normalizeDirection * Time.deltaTime * 30; 30 | } 31 | 32 | if (Timer > 3 && exploded == false) 33 | { 34 | Explode(); 35 | } 36 | } 37 | 38 | public override void OnCollisionEnter(Collision collision) 39 | { 40 | if (collision.gameObject != null && (collision.gameObject.name != "Bomb" && collision.gameObject.name != "Terrain" && collision.gameObject.GetComponent() !=null && weaponToStick != null && collision.gameObject.GetComponent() != weaponToStick.GetComponent().objectToStick.GetComponent())) 41 | if (playersBullet == false && collision.gameObject.tag == "Player" || playersBullet == true && collision.gameObject.tag != "Player" || playersBullet == false && collision.gameObject.tag != "Player") 42 | { 43 | Explode(); 44 | } 45 | } 46 | 47 | public override void Explode() 48 | { 49 | audio2.Play(); 50 | 51 | foreach (Transform child in gameObject.transform) 52 | { 53 | GameObject.Destroy(child.gameObject); 54 | } 55 | 56 | gameObject.transform.GetComponent().enabled = false; 57 | gameObject.transform.GetComponent().enabled = false; 58 | 59 | GameObject Explosions = Instantiate(explosionRocketPrefab, transform.position, Quaternion.Euler(0, 0, 0)); 60 | Destroy(Explosions, 2f); 61 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 50); 62 | 63 | foreach (Collider hit in colliders) 64 | { 65 | if ((hit.GetComponent() != null && hit.GetComponent() == null && hit.GetComponent() == null) && (hit.name != "Rocket")) 66 | hit.GetComponent().AddExplosionForce(800, gameObject.transform.position + new Vector3(0, 0, 0), 30, 1, ForceMode.Impulse); 67 | 68 | if (hit.GetComponent() != null && hit.gameObject != null) 69 | { 70 | if (weaponToStick != null && hit.transform.GetComponent().dead == false) 71 | hit.transform.GetComponent().whoIsDamaging = weaponToStick.GetComponent().objectToStick.gameObject; 72 | 73 | if (weaponToStick != null && weaponToStick.GetComponent().objectToStick.gameObject.name == "Player") 74 | { 75 | if (hit.transform.GetComponent().transform.tag != "Ship") 76 | hit.transform.GetComponent().TakeDamage(damage * 2f); 77 | else 78 | hit.transform.GetComponent().TakeDamage(damage / 10); 79 | } 80 | else if (weaponToStick != null) 81 | { 82 | if (hit.transform.GetComponent().transform.tag != "Ship") 83 | hit.transform.GetComponent().TakeDamage(damage); 84 | else 85 | hit.transform.GetComponent().TakeDamage(damage / 10); 86 | } 87 | } 88 | 89 | if (hit.GetComponent() != null) 90 | { 91 | hit.GetComponent().TakeDamage(damage); 92 | } 93 | } 94 | 95 | if (gameObject.GetComponent() != null) 96 | gameObject.GetComponent().enabled = false; 97 | 98 | if (gameObject.GetComponent() != null) 99 | gameObject.GetComponent().enabled = false; 100 | 101 | foreach (Transform child in transform) 102 | { 103 | if (child.GetComponent() != null) 104 | child.GetComponent().enabled = false; 105 | if (child.GetComponent() != null) 106 | child.GetComponent().enabled = false; 107 | } 108 | 109 | Destroy(gameObject, 3); 110 | exploded = true; 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/RocketShell.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | public class RocketShell : MonoBehaviour 7 | { 8 | public GameObject weaponToStick; 9 | public GameObject explosionRocketPrefab; 10 | 11 | public AudioSource audio; 12 | public AudioSource audio2; 13 | 14 | public float speed; 15 | public float damage; 16 | public float dmgRadius; 17 | public float Timer; 18 | 19 | public bool isProjectile; 20 | public bool isHoming; 21 | public bool playersBullet; 22 | 23 | public Rigidbody rb; 24 | 25 | public void FixedUpdate() 26 | { 27 | MoveBullet(); 28 | } 29 | 30 | public void LaunchSound() 31 | { 32 | audio.Play(); 33 | } 34 | 35 | public virtual void MoveBullet () 36 | { 37 | Timer += Time.deltaTime; 38 | 39 | if ((isProjectile==true) && (rb != null)) 40 | rb.AddRelativeForce(0, 0, speed += 24, ForceMode.Acceleration); 41 | 42 | if (playersBullet == true && isHoming == true) 43 | if (Physics.BoxCast(GameMaster.GM.player.transform.TransformPoint(0, 0, 0), new Vector3(20, 20, 2), transform.forward, out RaycastHit hitInfo2, Quaternion.Euler(0, 0, 0), 400, 1 << 8)) 44 | if ((hitInfo2.transform.tag == "Seeker" || hitInfo2.transform.tag == "Trooper")&&(hitInfo2.transform.GetComponent().factionId != 0)) 45 | { 46 | gameObject.transform.LookAt(hitInfo2.transform.position + new Vector3(0, 1, 0)); 47 | Vector3 normalizeDirection = (hitInfo2.transform.position + new Vector3(0, 1, 0) - gameObject.transform.position).normalized; 48 | gameObject.transform.position += normalizeDirection * Time.deltaTime * 30; 49 | } 50 | 51 | if (Timer > 5) 52 | Destroy(gameObject); 53 | } 54 | 55 | public virtual void Awake() 56 | { 57 | isProjectile = true; 58 | playersBullet = false; 59 | rb = gameObject.GetComponent(); 60 | } 61 | 62 | public virtual void OnCollisionEnter(Collision collision) 63 | { 64 | if (collision.gameObject.name != "Rocket") 65 | if (playersBullet == false && collision.gameObject.tag=="Player" || playersBullet == true && collision.gameObject.tag != "Player" || playersBullet == false && collision.gameObject.tag != "Player") 66 | { 67 | ContactPoint contact = collision.contacts[0]; 68 | Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal); 69 | Vector3 pos = contact.point; 70 | 71 | if (explosionRocketPrefab != null) 72 | { 73 | GameObject Explosions = Instantiate(explosionRocketPrefab, pos, Quaternion.Euler(0, 0, 0)); 74 | Destroy(Explosions, 2f); 75 | } 76 | 77 | Explode(); 78 | } 79 | } 80 | 81 | public virtual void Explode() 82 | { 83 | audio2.Play(); 84 | 85 | foreach (Transform child in gameObject.transform) 86 | { 87 | GameObject.Destroy(child.gameObject); 88 | } 89 | 90 | Collider ammoCollider = gameObject.transform.GetComponent(); 91 | 92 | ammoCollider.enabled = false; 93 | gameObject.transform.GetComponent().enabled = false; 94 | 95 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 35); 96 | 97 | foreach (Collider hit in colliders) 98 | { 99 | FactionIndex fractionHitObject = hit.GetComponent(); 100 | 101 | if ((hit.GetComponent() != null && hit.GetComponent() == null && hit.GetComponent() == null) && (hit.name != "Rocket") && (hit.name != "Bomb")) 102 | hit.GetComponent().AddExplosionForce(300, gameObject.transform.position + new Vector3(0, 0, 0), 20, 1, ForceMode.Impulse); 103 | 104 | if (fractionHitObject != null && hit.gameObject != null) 105 | { 106 | if (weaponToStick != null && fractionHitObject.dead == false) 107 | fractionHitObject.whoIsDamaging = weaponToStick.GetComponent().objectToStick.gameObject; 108 | 109 | if (weaponToStick != null && weaponToStick.GetComponent().objectToStick.gameObject.name == "Player") 110 | { 111 | if (fractionHitObject.transform.tag != "Ship") 112 | fractionHitObject.TakeDamage(damage * 2f); 113 | else 114 | fractionHitObject.TakeDamage(damage / 10); 115 | 116 | } 117 | else if (weaponToStick != null ) 118 | { 119 | if(fractionHitObject.transform.tag != "Ship") 120 | fractionHitObject.TakeDamage(damage); 121 | else 122 | fractionHitObject.TakeDamage(damage / 10); 123 | } 124 | } 125 | 126 | if (hit.GetComponent() != null) 127 | { 128 | hit.GetComponent().TakeDamage(damage); 129 | } 130 | } 131 | 132 | if (gameObject.GetComponent() != null) 133 | gameObject.GetComponent().enabled = false; 134 | 135 | if (ammoCollider != null) 136 | ammoCollider.enabled = false; 137 | 138 | foreach (Transform child in transform) 139 | { 140 | if (child.GetComponent() != null) 141 | child.GetComponent().enabled = false; 142 | if (child.GetComponent() != null) 143 | child.GetComponent().enabled = false; 144 | } 145 | 146 | Destroy(gameObject, 3); 147 | } 148 | } 149 | 150 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Trooper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Trooper : Seeker 6 | { 7 | public Vector3 pointFromShooting; 8 | public Vector3 pointFromShootingRandomize; 9 | public Vector3 pointToChase; 10 | 11 | public bool destinationPass; 12 | public bool wait; 13 | public bool foundTargetToAttack; 14 | public bool targetIsShip; 15 | public bool ignorePlayerCommandAndStay; 16 | public bool stopDoing; 17 | public bool rotateBody; 18 | 19 | public int attackTargetId; 20 | public int randomCollisionStuckDirection; 21 | 22 | public GameObject enemyToLook; 23 | public GameObject targetToChase; 24 | public GameObject targetToChaseByPlayerCommand; 25 | public GameObject teamSelectMark; 26 | public GameObject body; 27 | 28 | public float trooperSpeed; 29 | public float distToLerp; 30 | public float timer; 31 | float randomSpeedDeviation; 32 | 33 | public Rigidbody rbTrooper; 34 | 35 | public override void Awake() 36 | { 37 | level = 1; 38 | attackTargetId = Random.Range(0, 6); 39 | targetIsShip = true; 40 | health = 1500; 41 | maxHP = 1500; 42 | destinationPass = false; 43 | foundTargetToAttack = false; 44 | wait = false; 45 | distToLerp = 170; 46 | gameObject.tag = "Trooper"; 47 | wait = true; 48 | alreadyHaveWeapon = false; 49 | dead = false; 50 | foundObject = false; 51 | isVulnerable = true; 52 | 53 | textHP = Instantiate(GameMaster.GM.text3dDamage, transform.position + new Vector3(0, textHpHeight, 0), Quaternion.Euler(0, 0, 0)); 54 | textHP.gameObject.GetComponent().text = level.ToString(); 55 | textHP.transform.parent = transform; 56 | 57 | healthBarScaleMultiplier = 0.8f; 58 | healthBar = Instantiate(GameMaster.GM.healthBar, transform.position + new Vector3(0, healthBarHeight, 0), Quaternion.Euler(0, 0, 0)); 59 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.05f, 1); 60 | healthBar.transform.SetParent(gameObject.transform); 61 | pointFromShootingRandomize.Set(Random.Range(-40, 40), 0, Random.Range(-40, 40)); 62 | } 63 | 64 | public void Start() 65 | { 66 | randomSpeedDeviation = (float) Random.Range(0, 1000) / 1000 / 8; 67 | trooperSpeed += randomSpeedDeviation; 68 | 69 | randomCollisionStuckDirection = Random.Range(0, 2); 70 | 71 | if (randomCollisionStuckDirection == 0) 72 | randomCollisionStuckDirection = -1; 73 | if (randomCollisionStuckDirection == 1) 74 | randomCollisionStuckDirection = 1; 75 | 76 | InvokeRepeating("KeepFormation", 0, 0.3f); 77 | } 78 | 79 | public override void Update() 80 | { 81 | FindItemsAround(GameMaster.GM.globalObjectList, GameMaster.GM.platformObjectList); 82 | } 83 | 84 | public override void FindItemsAround(List _GlobalObjectList, List _PlatformList) 85 | { 86 | if (dead == false && stopDoing == false) 87 | { 88 | if (targetToChase != null) 89 | { 90 | if (targetToChase.GetComponent() != null) 91 | { 92 | pointFromShooting = targetToChase.transform.position - new Vector3(0, targetToChase.transform.position.y, 0); 93 | } 94 | else 95 | { 96 | if (targetToChase.GetComponent() != null) 97 | { 98 | if (gameObject.name == "LightShip") 99 | pointFromShooting = new Vector3(targetToChase.transform.position.x, targetToChase.transform.position.y, targetToChase.transform.position.z); 100 | if (gameObject.name == "Trooper") 101 | pointFromShooting = new Vector3(targetToChase.transform.position.x, transform.position.y, targetToChase.transform.position.z); 102 | } 103 | 104 | if (targetToChase.GetComponent() != null) 105 | { 106 | if (gameObject.name == "LightShip") 107 | pointFromShooting = new Vector3(targetToChase.transform.position.x, targetToChase.transform.position.y, targetToChase.transform.position.z); 108 | if (gameObject.name == "Trooper") 109 | pointFromShooting = new Vector3(targetToChase.transform.position.x, transform.position.y, targetToChase.transform.position.z); 110 | } 111 | } 112 | } 113 | else 114 | { 115 | if (pointToChase != new Vector3(0, 0, 0)) 116 | { 117 | pointFromShooting = pointToChase + pointFromShootingRandomize * 4; 118 | } 119 | else 120 | { 121 | if (factionId == 0 && GameMaster.GM.aiPlayerBase == false) 122 | { 123 | if (gameObject.name == "Trooper") 124 | pointFromShooting = new Vector3(GameMaster.GM.player.transform.position.x, transform.position.y, GameMaster.GM.player.transform.position.z) + pointFromShootingRandomize * 4; 125 | if (gameObject.name == "LightShip") 126 | pointFromShooting = new Vector3(GameMaster.GM.player.transform.position.x, GameMaster.GM.player.transform.position.y, GameMaster.GM.player.transform.position.z) + pointFromShootingRandomize * 4; 127 | } 128 | else 129 | { 130 | int rnDShip = Random.Range(0, GameMaster.GM.mainBaseCount); 131 | 132 | while (rnDShip == factionId) 133 | rnDShip = Random.Range(0, GameMaster.GM.mainBaseCount); 134 | 135 | if (GameMaster.GM.shipObjectList[rnDShip] != null) 136 | targetToChase = GameMaster.GM.shipObjectList[rnDShip]; 137 | 138 | if (factionId != 0 && GameMaster.GM.aiPlayerBase == false && GameMaster.GM.shipObjectList[rnDShip] != null) 139 | targetToChase = GameMaster.GM.shipObjectList[rnDShip]; 140 | } 141 | } 142 | } 143 | 144 | if (targetToChase != null && targetToChase.GetComponent() != null) 145 | pointFromShooting = pointFromShooting + pointFromShootingRandomize * 4; 146 | 147 | if (targetToChase != null && targetToChase.GetComponent() == null) 148 | pointFromShooting = pointFromShooting + pointFromShootingRandomize; 149 | 150 | if ((currentWeapon != null && enemyToLook != null) || (currentWeapon != null && enemyToLook != null) ) 151 | { 152 | if (gameObject.name == "Trooper") 153 | { 154 | body.transform.LookAt(enemyToLook.transform.position); 155 | 156 | if (rotateBody) 157 | body.transform.eulerAngles = body.transform.eulerAngles + new Vector3(0, 0, -90); 158 | 159 | wait = true; 160 | } 161 | else 162 | { 163 | Quaternion lookOnLook = Quaternion.LookRotation(enemyToLook.transform.position - transform.position); 164 | transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * 4); 165 | 166 | if (rotateBody) 167 | body.transform.eulerAngles = body.transform.eulerAngles + new Vector3(0, 0, -90); 168 | 169 | wait = true; 170 | } 171 | } 172 | else 173 | { 174 | wait = false; 175 | } 176 | 177 | // если враг мертв, то двигаться дальше 178 | if (enemyToLook != null && enemyToLook.GetComponent() != null && enemyToLook.GetComponent().dead == true && currentWeapon.GetComponent().playerFollowingCommand == true) 179 | wait = false; 180 | 181 | if ( ((Vector3.Distance(transform.position, pointFromShooting)) > 80) && (wait == false) ) 182 | { 183 | Quaternion lookOnLook = Quaternion.LookRotation(pointFromShooting - transform.position); 184 | transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * 4); 185 | 186 | rbTrooper.AddRelativeForce(Vector3.forward * trooperSpeed * Time.deltaTime * 40, ForceMode.VelocityChange); 187 | 188 | if (gameObject.GetComponent() != null) 189 | { 190 | gameObject.GetComponent().Play("Run_Guard"); 191 | gameObject.GetComponent().speed = 1 + randomSpeedDeviation; 192 | } 193 | } 194 | else 195 | { 196 | wait = true; 197 | 198 | if (enemyToLook == false) 199 | { 200 | Quaternion lookOnLook = Quaternion.LookRotation(Vector3.forward - transform.position); 201 | transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * 4); 202 | } 203 | 204 | if (gameObject.GetComponent() != null) 205 | gameObject.GetComponent().Play("Idle"); 206 | } 207 | 208 | if (((Vector3.Distance(transform.position, pointFromShooting)) > 120)) 209 | { 210 | wait = false; 211 | } 212 | } 213 | 214 | // Анимация смерти 215 | if (dead == true && stopDoing == false) 216 | { 217 | if (gameObject.GetComponent() != null) 218 | gameObject.GetComponent().Play("Idle"); 219 | 220 | stopDoing = true; 221 | } 222 | } 223 | 224 | public void KeepFormation() 225 | { 226 | if (wait == false) 227 | { 228 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 100); 229 | 230 | foreach (Collider hit in colliders) 231 | { 232 | if ((hit.GetComponent() != null) && (hit.name != "Rocket") && hit.GetComponent() == null && hit.GetComponent() != null) 233 | { 234 | if (hit.name == "LightShip") 235 | hit.GetComponent().AddExplosionForce(70, gameObject.transform.position + new Vector3(0, 0, 0), 0, 1, ForceMode.Force); 236 | if (hit.name == "Trooper") 237 | hit.GetComponent().AddExplosionForce(800, gameObject.transform.position + new Vector3(0, 0, 0), 0, 1, ForceMode.Force); 238 | } 239 | } 240 | } 241 | } 242 | 243 | public virtual void OnCollisionStay(Collision collisioninfo) 244 | { 245 | if (collisioninfo.gameObject.GetComponent() != null || collisioninfo.gameObject.GetComponent() != null || collisioninfo.gameObject.GetComponent() != null) 246 | { 247 | rbTrooper.AddRelativeForce(Vector3.left * 300 * Random.Range(-1, 2), ForceMode.Impulse); 248 | } 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Seeker.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Seeker : FactionIndex 6 | { 7 | public float minDistance; 8 | public int minDistNum; 9 | public int countOfItemsCollected; 10 | public int lootMinCount; 11 | 12 | public Vector3 currentTarget; 13 | 14 | public bool foundObject; 15 | public bool findNextObject = true; 16 | public bool goingToBase; 17 | public bool alreadyHaveWeapon; 18 | public bool isStationary; 19 | 20 | public GameObject textHP; 21 | public GameObject smoke; 22 | public GameObject currentTargetObject; 23 | public Weapon currentWeapon; 24 | 25 | public float timer2; 26 | 27 | public override void Awake() 28 | { 29 | timer2 = Random.Range(0, 100); 30 | level = 1; 31 | gameObject.tag = "Seeker"; 32 | minDistance = 1000; 33 | minDistNum = 0; 34 | countOfItemsCollected = 0; 35 | alreadyHaveWeapon = false; 36 | health = 100000; 37 | maxHP = 100000; 38 | dead = false; 39 | foundObject = false; 40 | isVulnerable = true; 41 | 42 | textHP = Instantiate(GameMaster.GM.text3dDamage, transform.position + new Vector3(0, textHpHeight, 0), Quaternion.Euler(0, 0, 0)); 43 | textHP.gameObject.GetComponent().text = level.ToString(); 44 | textHP.transform.parent = transform; 45 | 46 | healthBarScaleMultiplier = 10; 47 | healthBar = Instantiate(GameMaster.GM.healthBar, transform.position + new Vector3(0, healthBarHeight, 0), Quaternion.Euler(0, 0, 0)); 48 | healthBar.transform.SetParent(gameObject.transform); 49 | healthBar.transform.localScale = new Vector3(health/maxHP * healthBarScaleMultiplier, 0.05f, 1); 50 | } 51 | 52 | public virtual void Update() 53 | { 54 | FindItemsAround(GameMaster.GM.globalObjectList, GameMaster.GM.platformObjectList); 55 | } 56 | 57 | public override void TakeDamage(float damage) 58 | { 59 | if (isVulnerable == true) 60 | { 61 | if (health > damage) 62 | { 63 | if (whoIsDamaging != null && whoIsDamaging.GetComponent().factionId != GetComponent().factionId) 64 | health -= damage; 65 | 66 | textHP.gameObject.GetComponent().text = level.ToString(); 67 | 68 | if (healthBar != null) 69 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.02f, 1); 70 | } 71 | // Обездвижили 72 | else 73 | { 74 | if (dead == false) 75 | { 76 | if (healthBar != null) 77 | healthBar.transform.localScale = new Vector3(0, 0, 0); 78 | 79 | if (gameObject.GetComponent() == null && gameObject.GetComponent() != null) 80 | gameObject.GetComponent().AddForce(0, 800, 0, ForceMode.Impulse); 81 | 82 | StartCoroutine(Dying()); 83 | } 84 | 85 | dead = true; 86 | health -= damage; 87 | } 88 | } 89 | } 90 | 91 | public void Heal(float healpoints) 92 | { 93 | health += healpoints; 94 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 0.05f, 1); 95 | } 96 | 97 | public void SetHealth(float inputHealth) 98 | { 99 | health = inputHealth; 100 | } 101 | 102 | public virtual void FindItemsAround(List objectList, List platformList) 103 | { 104 | RaycastHit GroundHit; 105 | Physics.Raycast(transform.position, -transform.up, out GroundHit, 10); 106 | 107 | transform.position = new Vector3(transform.position.x, 20, transform.position.z); 108 | 109 | healthBar.transform.LookAt(Camera.main.transform.position, -Vector3.up); 110 | 111 | if (objectList.Count > 0 && dead == false) 112 | { 113 | if (findNextObject == true) 114 | { 115 | minDistNum = Random.Range(0, objectList.Count); 116 | } 117 | 118 | if (objectList[minDistNum] == null || objectList[minDistNum].GetComponent().factionId != 0 && objectList[minDistNum].GetComponent().factionId != factionId || currentTargetObject.gameObject == null) 119 | { 120 | findNextObject = true; 121 | } 122 | 123 | if (objectList[minDistNum] != null) 124 | { 125 | if ((objectList[minDistNum].gameObject.tag == "Follower" && objectList[minDistNum].GetComponent().followOwner == false) || (goingToBase == false && objectList[minDistNum].gameObject.name == "Roller" && objectList[minDistNum].gameObject.GetComponent() != null)) 126 | foundObject = true; 127 | else 128 | foundObject = false; 129 | 130 | if (objectList[minDistNum].gameObject.tag == "Follower" && findNextObject == false && objectList[minDistNum].GetComponent().followOwner == true) 131 | findNextObject = true; 132 | 133 | if (foundObject == true && goingToBase == false) 134 | { 135 | findNextObject = false; 136 | 137 | if(objectList[minDistNum].gameObject != null) 138 | { 139 | currentTarget = objectList[minDistNum].transform.position; 140 | currentTargetObject = objectList[minDistNum].gameObject; 141 | } 142 | else 143 | minDistNum = Random.Range(0, objectList.Count); 144 | 145 | Quaternion lookOnLook = Quaternion.LookRotation(new Vector3(currentTarget.x, transform.position.y, currentTarget.z) - transform.position); 146 | transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * 3f); 147 | Vector3 normalizeDirection = (objectList[minDistNum].gameObject.GetComponent().transform.position - gameObject.transform.position).normalized; 148 | gameObject.GetComponent().transform.position += normalizeDirection * Time.deltaTime * 70; 149 | } 150 | } 151 | 152 | if (goingToBase == true && platformList[factionId].gameObject != null) 153 | { 154 | currentTarget = new Vector3(platformList[factionId].transform.position.x, transform.position.y, platformList[factionId].transform.position.z); 155 | 156 | Quaternion lookOnLook = Quaternion.LookRotation(new Vector3(currentTarget.x, transform.position.y, currentTarget.z) - transform.position); 157 | transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * 3f); 158 | Vector3 normalizeDirection = (platformList[factionId].gameObject.GetComponent().transform.position - gameObject.transform.position).normalized; 159 | gameObject.GetComponent().transform.position += normalizeDirection * Time.deltaTime * 70; 160 | } 161 | 162 | if (countOfItemsCollected >= 8) 163 | goingToBase = true; 164 | else if (countOfItemsCollected == 0) 165 | goingToBase = false; 166 | else if (countOfItemsCollected != 0 && currentTargetObject == null) 167 | goingToBase = false; 168 | 169 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 80, 1 << 9); 170 | 171 | foreach (Collider hit in colliders) 172 | if (gameObject.tag == "Seeker" && hit.tag == "Follower" && dead == false) 173 | { 174 | Vector3 normalizeDirection = (gameObject.transform.position - hit.transform.position).normalized; 175 | hit.transform.position += normalizeDirection * Time.deltaTime * hit.GetComponent().speed * 2; 176 | } 177 | 178 | if (findNextObject == false && foundObject == false) 179 | { 180 | findNextObject = true; 181 | } 182 | } 183 | } 184 | 185 | IEnumerator Dying() 186 | { 187 | yield return new WaitForSeconds(0f); 188 | 189 | if (whoIsDamaging != null) 190 | if (whoIsDamaging.GetComponent().level < 5) 191 | { 192 | whoIsDamaging.GetComponent().level += 1; 193 | 194 | if (whoIsDamaging.GetComponent() != null) 195 | whoIsDamaging.GetComponent().textHP.gameObject.GetComponent().text = level.ToString(); 196 | } 197 | 198 | if (whoIsDamaging != null && (whoIsDamaging.tag == "Trooper" || whoIsDamaging.tag == "Seeker")) 199 | { 200 | whoIsDamaging.GetComponent().health += 1000; 201 | whoIsDamaging.GetComponent().maxHP += 1000; 202 | } 203 | 204 | if (whoIsDamaging != null && whoIsDamaging.tag == "Player") 205 | { 206 | whoIsDamaging.GetComponent().health += 200; 207 | whoIsDamaging.GetComponent().maxHP += 1000; 208 | GameMaster.GM.player.GetComponent().playerHealth3dText.text = $"HP: {GameMaster.GM.player.GetComponent().health}"; 209 | } 210 | 211 | totallyDead = true; 212 | 213 | if (GetComponent() != null) 214 | GetComponent().Play(); 215 | 216 | GameObject Explode = Instantiate(deathEffect, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 217 | 218 | Destroy(Explode, 2f); 219 | 220 | if (lootAfterDeath == true && whoIsDamaging.gameObject!= null && whoIsDamaging.GetComponent() != null) 221 | { 222 | int rndLootCount = Random.Range(lootMinCount, lootMinCount + (int) gameObject.GetComponent().level); 223 | 224 | for (int i = 0; i < rndLootCount; i++) 225 | { 226 | int rndNum = Random.Range(0, GameMaster.GM.detailsList.Count); 227 | 228 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.detailsList[rndNum], transform.position + new Vector3(Random.Range(-4, 4), Random.Range(0, 7), Random.Range(-4, 4)), Quaternion.Euler(0, 0, 0), "Follower", GameMaster.GM.globalObjectList); 229 | 230 | if (createdObject.GetComponent() == null) 231 | { 232 | createdObject.AddComponent(); 233 | } 234 | 235 | createdObject.GetComponent().mass = 5; 236 | createdObject.GetComponent().useGravity = true; 237 | createdObject.GetComponent().angularDrag = 0.05f; 238 | createdObject.GetComponent().drag = 1f; 239 | 240 | if (createdObject.GetComponent() != null && createdObject.GetComponent().convex == false) 241 | createdObject.GetComponent().convex = true; 242 | 243 | createdObject.GetComponent().moveToNextOwner = true; 244 | } 245 | } 246 | 247 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 50); 248 | 249 | foreach (Collider hit in colliders) 250 | { 251 | if ((hit.GetComponent() != null) && (hit.tag != "Rocket")) 252 | hit.GetComponent().AddExplosionForce(300, gameObject.transform.position, 100, Random.Range(0, 1), ForceMode.Impulse); 253 | } 254 | 255 | GameMaster.GM.RecursiveDestroy(transform, gameObject, 4); 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/GameMaster.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.SceneManagement; 5 | using UnityEngine.UI; 6 | 7 | /// 8 | /// Class for global variables and functions 9 | /// 10 | /// \code 11 | /// sdfsdfsdfsd 12 | /// fsdfsdf 13 | /// sdf 14 | /// \endcode 15 | /// 16 | [RequireComponent(typeof(AudioSource))] 17 | public class GameMaster : MonoBehaviour 18 | { 19 | public static GameMaster GM; 20 | 21 | /// 22 | /// AI-based simulation without player 23 | /// 24 | public bool aiPlayerBase; 25 | 26 | /// 27 | /// Count of base ships (including player's) 28 | /// 29 | public int mainBaseCount; 30 | public int startMoney; 31 | public int unitsCount; 32 | public int attackProbability; 33 | 34 | public List fractionColors; 35 | 36 | /// 37 | /// Player health 38 | /// 39 | public Text playerHp; 40 | 41 | /// 42 | /// Player's main ship health 43 | /// 44 | public Text playerShipHp; 45 | 46 | /// 47 | /// Player money text 48 | /// 49 | public Text playerMoneyText; 50 | 51 | /// 52 | /// The enemy money text 53 | /// 54 | public Text enemyMoneyText; 55 | 56 | /// 57 | /// Small explosion effect 58 | /// 59 | public GameObject effectBoom; 60 | 61 | /// 62 | /// Effect for player and enemy death 63 | /// 64 | public GameObject enemyDestroy; 65 | 66 | /// 67 | /// Text with health above main bases 68 | /// 69 | public GameObject text3dDamage; 70 | 71 | /// 72 | /// Smoke after death 73 | /// 74 | public GameObject smokeAfterDeath; 75 | 76 | /// 77 | /// Main camera 78 | /// 79 | public GameObject myCamera; 80 | 81 | /// 82 | /// Spawn platform 83 | /// 84 | public GameObject spawnPlatform; 85 | 86 | /// 87 | /// Seeker prefab 88 | /// 89 | public GameObject seekerPrefab; 90 | 91 | /// 92 | /// Rocket launcher prefab 93 | /// 94 | public GameObject rocketLauncherPrefab; 95 | 96 | /// 97 | /// Rocket launcher mini prefab 98 | /// 99 | public GameObject rocketLauncherMiniPrefab; 100 | 101 | /// 102 | /// Bomb launcher prefab 103 | /// 104 | public GameObject bombLauncherPrefab; 105 | 106 | /// 107 | /// Machine gun prefab 108 | /// 109 | public GameObject machineGunPrefab; 110 | 111 | /// 112 | /// Trooper prefab 113 | /// 114 | public GameObject trooperPrefab; 115 | 116 | /// 117 | /// Trooper prefab 118 | /// 119 | public GameObject rollerEnemyBasePrefab; 120 | 121 | /// 122 | /// Tower prefab 123 | /// 124 | public GameObject TowerPrefab; 125 | 126 | /// 127 | /// Tower with gun prefab 128 | /// 129 | public GameObject TowerGunPrefab; 130 | 131 | /// 132 | /// FLight ship prefab 133 | /// 134 | public GameObject lightShipPrefab; 135 | 136 | /// 137 | /// Main ship base prefab 138 | /// 139 | public GameObject shipPrefab; 140 | 141 | /// 142 | /// Platform prefab for collecting resources 143 | /// 144 | public GameObject platformPrefab; 145 | 146 | /// 147 | /// Barracs prefab 148 | /// 149 | public GameObject trooperBase; 150 | 151 | /// 152 | /// Factory prefab 153 | /// 154 | public GameObject factoryPrefab; 155 | 156 | /// 157 | /// Healthbar above all units 158 | /// 159 | public GameObject healthBar; 160 | 161 | /// 162 | /// Team select sprite 163 | /// 164 | public GameObject teamSelect; 165 | public GameObject teamSelectSphere; 166 | 167 | /// 168 | /// Team marker sprite 169 | /// 170 | public GameObject teamMarker; 171 | 172 | /// 173 | /// Global object list 174 | /// 175 | public List globalObjectList; 176 | 177 | /// 178 | /// Rockets object list 179 | /// 180 | public List bulletObjectList; 181 | 182 | /// 183 | /// Weapon object list 184 | /// 185 | public List weaponObjectList; 186 | 187 | /// 188 | /// Main ship object list 189 | /// 190 | public List shipObjectList; 191 | 192 | /// 193 | /// Platform object list 194 | /// 195 | public List platformObjectList; 196 | 197 | /// 198 | /// Unit list 199 | /// 200 | public List unitList; 201 | 202 | /// 203 | /// Trooper barracs list 204 | /// 205 | public List trooperBaseList; 206 | 207 | /// 208 | /// Resources list (followers) 209 | /// 210 | public List detailsList; 211 | 212 | /// 213 | /// Player object 214 | /// 215 | public Transform player; 216 | 217 | /// 218 | /// To shake a camera 219 | /// 220 | public bool shakeCamera; 221 | 222 | /// 223 | /// Timer 224 | /// 225 | public float timer; 226 | 227 | /// 228 | /// Total number of cubes 229 | /// 230 | public int numCubes; 231 | 232 | /// 233 | /// Boom sound 234 | /// 235 | public AudioSource boomSound; 236 | 237 | /// 238 | /// Enemy explode sound 239 | /// 240 | public AudioClip explodeEnemySound; 241 | 242 | void Awake() 243 | { 244 | if (GM != null) 245 | GameObject.Destroy(GM); 246 | else 247 | GM = this; 248 | 249 | //DontDestroyOnLoad(this); 250 | 251 | if (Settings.SET != null) 252 | { 253 | mainBaseCount = Settings.SET.mainBaseCount; 254 | startMoney = Settings.SET.startMoney; 255 | unitsCount = Settings.SET.unitsCount; 256 | attackProbability = Settings.SET.attackProbability; 257 | aiPlayerBase = Settings.SET.aiPlayerBase; 258 | } 259 | else 260 | { 261 | mainBaseCount = 3; 262 | startMoney = 30; 263 | unitsCount = 100; 264 | attackProbability = 15; 265 | } 266 | } 267 | 268 | public void SetFactionColors () 269 | { 270 | fractionColors = new List(); 271 | List importantColors = new List(); 272 | 273 | importantColors.Add(new Color(0, 1, 1, 1f)); 274 | importantColors.Add(new Color(0, 1, 0.2f, 1f)); 275 | importantColors.Add(new Color(1, 1, 0, 1f)); 276 | importantColors.Add(new Color(1, 0, 0, 1f)); 277 | importantColors.Add(new Color(1, 0, 1, 1f)); 278 | importantColors.Add(new Color(1, 1, 1, 1f)); 279 | 280 | for (int i = 0; i < GameMaster.GM.mainBaseCount; i++) 281 | { 282 | float r, g, b; 283 | 284 | r = (float)(Random.Range(0, 255) / 255f); 285 | g = (float)(Random.Range(0, 255) / 255f); 286 | b = (float)(Random.Range(0, 255) / 255f); 287 | 288 | Color newRandomColor = new Color(r, g, b, 1f); 289 | fractionColors.Add(newRandomColor); 290 | } 291 | 292 | for (int i = 0; i < fractionColors.Count; i++) 293 | { 294 | if (i <= 4) 295 | fractionColors[i] = importantColors[i]; 296 | } 297 | } 298 | 299 | /// 300 | /// A custom constructor for objects 301 | /// 302 | /// The prefab. 303 | /// Random width range for spawning. 304 | /// Random length range for spawning. 305 | /// Spawning height. 306 | /// Quaternion. 307 | /// Name of the object. 308 | /// A list to add created object. 309 | /// 310 | public GameObject ConstructObject(GameObject prefab, float spawnWidth, float SpawnLength, float height, Quaternion Q, string objectName, List listToAdd) 311 | { 312 | Vector3 RandomSpawnPosition = new Vector3(Random.Range(spawnWidth, SpawnLength), height, Random.Range(spawnWidth, SpawnLength)); 313 | GameObject CreatedObject = Instantiate(prefab, RandomSpawnPosition, Q) as GameObject; 314 | CreatedObject.gameObject.name = objectName; 315 | listToAdd.Add(CreatedObject); 316 | numCubes++; 317 | return CreatedObject; 318 | } 319 | 320 | /// 321 | /// ConstructObject method overload for fixed Vector3 SpawnPosition. 322 | /// 323 | public GameObject ConstructObject(GameObject prefab, Vector3 spawnPosition, Quaternion Q, string objectName, List listToAdd, bool renderMesh = true) 324 | { 325 | GameObject CreatedObject = Instantiate(prefab, spawnPosition, Q) as GameObject; 326 | CreatedObject.gameObject.name = objectName; 327 | listToAdd.Add(CreatedObject); 328 | numCubes++; 329 | 330 | if (CreatedObject.GetComponent() != null) 331 | CreatedObject.GetComponent().enabled = renderMesh; 332 | 333 | Component[] renderer; 334 | 335 | if(CreatedObject.GetComponentsInChildren() != null) 336 | { 337 | renderer = CreatedObject.GetComponentsInChildren(); 338 | 339 | for (int i = 0; i < renderer.Length; i++) 340 | { 341 | if (renderer[i].gameObject.name == "Laser_Gun") 342 | renderer[i].GetComponent().enabled = renderMesh; 343 | } 344 | } 345 | 346 | return CreatedObject; 347 | } 348 | 349 | public void PlayEnemyExplosionSound(Vector3 position) 350 | { 351 | AudioSource.PlayClipAtPoint(explodeEnemySound, position); 352 | } 353 | 354 | /// 355 | /// Recursive destroying. Used for destroy all object childs. 356 | /// 357 | /// Object Transform to destroy. 358 | /// Game object to destroy. 359 | /// Time to destroy object. 360 | public void RecursiveDestroy (Transform objectTransform, GameObject gameObj, float timeToDestroy) 361 | { 362 | foreach (Transform child in objectTransform) 363 | { 364 | if (child.GetComponent() != null) 365 | child.GetComponent().enabled = false; 366 | 367 | if (child.GetComponent() != null) 368 | child.GetComponent().enabled = false; 369 | 370 | if (child.GetComponent() != null) 371 | child.GetComponent().enabled = false; 372 | 373 | if (child.GetComponent() != null) 374 | child.GetComponent().enabled = false; 375 | 376 | if (child.GetComponent() != null) 377 | child.GetComponent().Stop(); 378 | 379 | RecursiveDestroy(child, gameObj, timeToDestroy); 380 | } 381 | 382 | if (gameObj.GetComponent() != null) 383 | gameObj.GetComponent().enabled = false; 384 | 385 | if (gameObj.GetComponent() == null) 386 | Destroy(gameObj, timeToDestroy); 387 | } 388 | 389 | /// 390 | /// Gives weapon to selected object. 391 | /// 392 | /// The object position. 393 | public void GiveWeaponToObject (Vector3 objectPosition) 394 | { 395 | int rnd = Random.Range(0, 100); 396 | 397 | if (rnd >= 65 && rnd < 100) 398 | GameMaster.GM.ConstructObject(GameMaster.GM.rocketLauncherMiniPrefab, objectPosition, Quaternion.Euler(0, 0, 0), "RocketLauncher", GameMaster.GM.weaponObjectList, false); 399 | 400 | if (rnd >= 30 && rnd < 65) 401 | GameMaster.GM.ConstructObject(GameMaster.GM.rocketLauncherPrefab, objectPosition, Quaternion.Euler(0, 0, 0), "RocketLauncher", GameMaster.GM.weaponObjectList, false); 402 | 403 | if (rnd <= 30) 404 | GameMaster.GM.ConstructObject(GameMaster.GM.machineGunPrefab, objectPosition, Quaternion.Euler(0, 0, 0), "MachineGun", GameMaster.GM.weaponObjectList, false); 405 | } 406 | 407 | public void FixedUpdate() 408 | { 409 | timer += Time.deltaTime; 410 | } 411 | } 412 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Follower.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Follower : FactionIndex 6 | { 7 | public float speed; 8 | public float jumpPower; 9 | public bool followOwner; 10 | public bool followOwnerCharger; 11 | public bool jumping; 12 | public bool moveToNextOwner; 13 | public GameObject pickUpEffect; 14 | public GameObject ownerToFollow; 15 | public GameObject chargerToFollow; 16 | public AudioSource audioPickEnemyCube; 17 | public AudioSource audioPickCubeToMe; 18 | public AudioSource audioPickShipCube; 19 | int rndDestroyTime; 20 | 21 | public override void Awake() 22 | { 23 | rndDestroyTime = Random.Range(0, 20); 24 | health = 50; 25 | maxHP = 50; 26 | gameObject.tag = "Follower"; 27 | jumpPower = 15; 28 | speed = 50; 29 | followOwner = false; 30 | factionId = 10; 31 | followOwnerCharger = false; 32 | jumping = true; 33 | isSimpleFollower = true; 34 | isVulnerable = false; 35 | } 36 | 37 | public void FixedUpdate() 38 | { 39 | MoveTo(); 40 | InvokeRepeating("CheckForDestroy", 10f + rndDestroyTime, 1f); 41 | } 42 | 43 | public virtual void MoveTo() 44 | { 45 | if (followOwner == true) // Если двигаться к владельцу (определяется в Collision ниже) 46 | { 47 | Vector3 normalizeDirection; // Направление движения 48 | float xpos = gameObject.GetComponent().transform.position.x; 49 | float zpos = gameObject.GetComponent().transform.position.z; 50 | 51 | if (ownerToFollow != null) 52 | { 53 | if (ownerToFollow.GetComponent() != null) // Если владелец куба - игрок ... 54 | normalizeDirection = (ownerToFollow.transform.TransformPoint(0, 0, -12000) - gameObject.GetComponent().transform.position + new Vector3(0, 3, 0)).normalized; // ... то двигаться к точке позади игрока 55 | else // Если владелец куба - не игрок ... 56 | normalizeDirection = (ownerToFollow.transform.TransformPoint(0, 5, -100) - gameObject.GetComponent().transform.position + new Vector3(0, 3, 0)).normalized; // ... то двигаться к точке позади владельца 57 | 58 | if (ownerToFollow.gameObject.tag == "Seeker") 59 | transform.position += normalizeDirection * Time.deltaTime * speed * 1.5f; // Сближать координату куба с Seeker или Player (перемещать куб) 60 | 61 | if (ownerToFollow.gameObject.tag == "Player") 62 | transform.position += normalizeDirection * Time.deltaTime * speed * 2f; // Сближать координату куба с Seeker или Player (перемещать куб) 63 | 64 | if (ownerToFollow.gameObject.tag != "Player" && ownerToFollow.gameObject.tag != "Seeker") 65 | transform.position += normalizeDirection * Time.deltaTime * speed * 1f; // Сближать координату куба с Seeker или Player (перемещать куб) 66 | } 67 | 68 | if (ownerToFollow != null) 69 | if (ownerToFollow.GetComponent() != null) // Если владелец - Seeker ... 70 | if (ownerToFollow.GetComponent().totallyDead == true) // ... и он мертв ... 71 | { 72 | if (gameObject.GetComponentsInChildren() != null) 73 | { 74 | int lightsCount = gameObject.GetComponentsInChildren().Length; 75 | 76 | for (int i = 0; i < lightsCount; i++) 77 | { 78 | //gameObject.GetComponentsInChildren()[i].color = Color.white; 79 | } 80 | } 81 | 82 | if (ownerToFollow.GetComponent().whoIsDamaging!=null) 83 | { 84 | ownerToFollow = ownerToFollow.GetComponent().whoIsDamaging; 85 | factionId = 10; // Установить идентификатор FractionId 86 | moveToNextOwner = true; 87 | StartCoroutine(MoveToNextOwnerTrigger()); 88 | gameObject.tag = "Follower"; // вернуть тэг кубу Follower 89 | } 90 | else 91 | { 92 | followOwner = false; // убрать владельца 93 | gameObject.tag = "Follower"; // вернуть тэг кубу Follower 94 | factionId = 10; 95 | } 96 | } 97 | 98 | for (int i = 0; i < GameMaster.GM.platformObjectList.Count; i++) // Цикл по всем платформам 99 | { 100 | if (GameMaster.GM.platformObjectList[i] != null) 101 | if ((xpos > GameMaster.GM.platformObjectList[i].transform.position.x - GameMaster.GM.platformObjectList[i].transform.lossyScale.x / 2) && (xpos < GameMaster.GM.platformObjectList[i].transform.position.x + GameMaster.GM.platformObjectList[i].transform.lossyScale.x / 2) && 102 | (zpos > GameMaster.GM.platformObjectList[i].transform.position.z - GameMaster.GM.platformObjectList[i].transform.lossyScale.z / 2) && (zpos < GameMaster.GM.platformObjectList[i].transform.position.z + GameMaster.GM.platformObjectList[i].transform.lossyScale.z / 2)) // Если куб над или под платформой i ... 103 | { 104 | chargerToFollow = GameMaster.GM.platformObjectList[i]; // ... то установить платформу к которой двигаться ChargerToFollow 105 | 106 | followOwnerCharger = true; // Если над или под платформой, то команда двигаться к платформе = true ... 107 | followOwner = false; // ... и перестать следовать за владельцем 108 | } 109 | } 110 | 111 | if (moveToNextOwner == true) 112 | { 113 | MoveAfterOwnerDeath(); 114 | } 115 | } 116 | 117 | if (followOwnerCharger == true && chargerToFollow.gameObject != null) // Если двигаться к платформе 118 | { 119 | Vector3 normalizeDirection = (chargerToFollow.transform.position - gameObject.GetComponent().transform.position + new Vector3(0, 8, 0)).normalized; // ... то определить направление и ... 120 | gameObject.GetComponent().transform.position += normalizeDirection * Time.deltaTime * speed * 2; // ... сближаться с платформой 121 | gameObject.GetComponent().AddForce(0, 1000, 0); // Подталкивать куб вверх для столкновения с Ship 122 | } 123 | } 124 | 125 | public void JumpAnimation() 126 | { 127 | if (gameObject.GetComponent() != null && jumping == true) 128 | { 129 | gameObject.GetComponent().GetComponent().AddForce(0, Random.Range(-jumpPower, jumpPower), 0, ForceMode.Impulse); 130 | gameObject.GetComponent().GetComponent().AddForce(Random.Range(-jumpPower, jumpPower / 10), 0, 0, ForceMode.Impulse); 131 | gameObject.GetComponent().GetComponent().AddForce(0, 0, Random.Range(-jumpPower, jumpPower), ForceMode.Impulse); 132 | } 133 | } 134 | 135 | public void MoveAfterOwnerDeath () 136 | { 137 | speed = 60; 138 | 139 | gameObject.GetComponent().mass = 5; 140 | gameObject.GetComponent().angularDrag = 1; 141 | //gameObject.GetComponent().useGravity = false; 142 | Vector3 normalizeDirection; 143 | 144 | if (ownerToFollow != null) 145 | { 146 | normalizeDirection = (ownerToFollow.transform.position - gameObject.GetComponent().transform.position).normalized; ; // движемся к тому, кто убил владельца 147 | gameObject.GetComponent().transform.position += normalizeDirection * Time.deltaTime * speed; // ... сближаться с новым владельцем 148 | } 149 | } 150 | 151 | IEnumerator MoveToNextOwnerTrigger() 152 | { 153 | //yield return new WaitForSeconds(0.8f); 154 | yield return new WaitForSeconds(0); 155 | moveToNextOwner = false; 156 | speed = 50; 157 | //gameObject.GetComponent().useGravity = true; 158 | gameObject.GetComponent().mass = 5; 159 | 160 | if (factionId == 10) 161 | followOwner = false; 162 | } 163 | 164 | public void CheckForDestroy() 165 | { 166 | if (ownerToFollow == null) 167 | { 168 | Destroy(gameObject); 169 | } 170 | } 171 | 172 | public virtual void OnCollisionEnter(Collision collisioninfo) 173 | { 174 | if (collisioninfo.gameObject.tag == "Terrain" && jumping == true) 175 | { 176 | gameObject.GetComponent().GetComponent().AddForce(0, Random.Range(4, jumpPower * 6), 0, ForceMode.Impulse); 177 | gameObject.GetComponent().GetComponent().AddForce(Random.Range(-jumpPower, jumpPower), 0, 0, ForceMode.Impulse); 178 | gameObject.GetComponent().GetComponent().AddForce(0, 0, Random.Range(-jumpPower, jumpPower), ForceMode.Impulse); 179 | } 180 | 181 | if (collisioninfo.gameObject.tag == "Seeker") // Если куб столкнулся с Seeker или Player ... 182 | { 183 | if (gameObject.GetComponent().factionId == 10) // ... и его индекс равен 10 (свободный) 184 | { 185 | gameObject.GetComponent().SetFractionId(collisioninfo.gameObject.GetComponent().factionId); // установить индекс равный Seeker или Player 186 | 187 | if (collisioninfo.gameObject.GetComponent() != null) // Если столкновение с Seeker, то ... 188 | { 189 | Seeker Seeker = collisioninfo.gameObject.GetComponent(); 190 | Seeker.findNextObject = true; // Команда Seeker для поиска нового куба 191 | Seeker.countOfItemsCollected++; // Счетчик подобранных кубов++ 192 | } 193 | 194 | // if (collisioninfo.gameObject.GetComponent() != null) // Если столкновение с Player, то ... 195 | // collisioninfo.gameObject.GetComponent().Heal(20); // Лечение Player 196 | 197 | ownerToFollow = collisioninfo.collider.gameObject; // Присвоить кубу владельца OwnerToFollow (Seeker или Player) 198 | 199 | if (gameObject.GetComponentsInChildren() != null) 200 | { 201 | int lightsCount = gameObject.GetComponentsInChildren().Length; 202 | 203 | for (int i = 0; i < lightsCount; i++) 204 | { 205 | gameObject.GetComponentsInChildren()[i].color = GameMaster.GM.fractionColors[this.factionId]; 206 | } 207 | } 208 | 209 | gameObject.GetComponent().followOwner = true; // Двигаться к владельцу = true 210 | gameObject.GetComponent().followOwnerCharger = false; // Двигаться к площадке = false 211 | gameObject.tag = "OwnedFollower"; // Изменить тег куба на OwnedFollower (имеет владельца) 212 | //gameObject.GetComponent().useGravity = false; 213 | 214 | ContactPoint contact = collisioninfo.contacts[0]; 215 | Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal); 216 | Vector3 pos = contact.point; 217 | gameObject.GetComponent().Play(); 218 | audioPickEnemyCube.Play(); 219 | } 220 | } 221 | else if (gameObject.GetComponent().factionId == 10 && collisioninfo.gameObject.tag == "Player") 222 | { 223 | gameObject.GetComponent().Play(); 224 | audioPickEnemyCube.Play(); 225 | 226 | if (collisioninfo.gameObject.GetComponent() != null && collisioninfo.gameObject.GetComponent().currentWeapon != null) 227 | collisioninfo.gameObject.GetComponent().currentWeapon.ownerLevel = level; 228 | 229 | // GameMaster.GM.RecursiveDestroy(transform, gameObject, 0.2f); 230 | 231 | gameObject.GetComponent().SetFractionId(collisioninfo.gameObject.GetComponent().factionId); 232 | ownerToFollow = collisioninfo.collider.gameObject; 233 | 234 | if (gameObject.GetComponentsInChildren() != null) 235 | { 236 | int lightsCount = gameObject.GetComponentsInChildren().Length; 237 | 238 | for (int i = 0; i < lightsCount; i++) 239 | { 240 | gameObject.GetComponentsInChildren()[i].color = GameMaster.GM.fractionColors[this.factionId]; 241 | } 242 | } 243 | 244 | gameObject.GetComponent().followOwner = true; // Двигаться к владельцу = true 245 | gameObject.GetComponent().followOwnerCharger = false; // Двигаться к площадке = false 246 | gameObject.tag = "OwnedFollower"; // Изменить тег куба на OwnedFollower (имеет владельца) 247 | //gameObject.GetComponent().useGravity = false; 248 | 249 | ContactPoint contact = collisioninfo.contacts[0]; 250 | Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal); 251 | Vector3 pos = contact.point; 252 | gameObject.GetComponent().Play(); 253 | audioPickEnemyCube.Play(); 254 | } 255 | 256 | 257 | if (collisioninfo.gameObject.tag == "Ship" && gameObject.tag == "OwnedFollower") 258 | { 259 | if (ownerToFollow != null) 260 | { 261 | if (ownerToFollow.GetComponent() != null) // Если владелец куба - Seeker ... 262 | { 263 | ownerToFollow.GetComponent().countOfItemsCollected--; // ... то вычесть счетчик-- 264 | //ownerToFollow.GetComponent().Heal(10); 265 | } 266 | } 267 | 268 | gameObject.transform.position = new Vector3(Random.Range(-700, 700), 200, Random.Range(-700, 700)); 269 | factionId = 10; 270 | 271 | //gameObject.GetComponent().material.color = Color.white; 272 | 273 | if (gameObject.GetComponentsInChildren() != null) 274 | { 275 | int lightsCount = gameObject.GetComponentsInChildren().Length; 276 | 277 | for (int i = 0; i < lightsCount; i++) 278 | { 279 | gameObject.GetComponentsInChildren()[i].color = Color.white; 280 | } 281 | } 282 | 283 | gameObject.GetComponent().followOwner = false; 284 | gameObject.GetComponent().followOwnerCharger = false; 285 | gameObject.transform.localScale += new Vector3(0f, 0f, 0f); 286 | gameObject.tag = "Follower"; 287 | 288 | if (collisioninfo.gameObject != null) 289 | { 290 | collisioninfo.gameObject.GetComponent().EarnMoney(500); 291 | collisioninfo.gameObject.GetComponent().Heal(1000); 292 | } 293 | 294 | 295 | audioPickShipCube.Play(); 296 | GameMaster.GM.RecursiveDestroy(transform, gameObject, 1); 297 | } 298 | 299 | if (collisioninfo.gameObject.tag == "Ship" && gameObject.tag == "Follower") 300 | gameObject.transform.position = new Vector3(Random.Range(-900, 900), 50, Random.Range(-900, 900)); 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Main.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class Main : MonoBehaviour 7 | { 8 | public int numCubes; 9 | 10 | public float spawnCircleAngle; 11 | public float spawnCircleAngle2; 12 | 13 | public Vector3 warriorPosition; 14 | public Vector3 randomSpawnPosition; 15 | 16 | public GameObject spawnPlatform; 17 | 18 | public Text statsText; 19 | 20 | void Start() 21 | { 22 | Time.timeScale = 1; 23 | Cursor.visible = false; 24 | Cursor.lockState = CursorLockMode.Locked; 25 | 26 | spawnPlatform = GameMaster.GM.ConstructObject(GameMaster.GM.spawnPlatform, new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0), "SpawnPlatform", GameMaster.GM.globalObjectList); 27 | 28 | InvokeRepeating("UpdateStats", 0f, 1f); 29 | InvokeRepeating("GenerateCubes", 0f, 0.3f); 30 | //InvokeRepeating("GenerateRollerBalls", 0f, 10f); 31 | 32 | GameMaster.GM.SetFactionColors(); 33 | 34 | SetupFactionsAndPlayer(GameMaster.GM.mainBaseCount); 35 | CreateShipPlatforms(); 36 | CreateSeekers(2); 37 | 38 | //CreateResources(1000); 39 | //CreateRollerBalls(20); 40 | //CreateWeapons(100); 41 | //CreateTroopers(20); 42 | //CreateLightShips(10); 43 | } 44 | 45 | public void SetupFactionsAndPlayer(int baseCount) 46 | { 47 | for (int i = 0; i < baseCount; i++) 48 | { 49 | GameObject newShipObject = GameMaster.GM.ConstructObject(GameMaster.GM.shipPrefab, new Vector3(2500 * Mathf.Cos(spawnCircleAngle * 3.14f / 180), 110, 2500 * Mathf.Sin(spawnCircleAngle * 3.14f / 180)), Quaternion.Euler(0, Random.Range(-180, 180), 0), "Seeker", GameMaster.GM.shipObjectList); 50 | newShipObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); 51 | newShipObject.GetComponent().SetFractionId(i); 52 | 53 | if (i == 0) 54 | { 55 | GameMaster.GM.shipObjectList[0].GetComponent().shipIsDeadEvent += printDeadHandler; 56 | GameMaster.GM.player.transform.position = GameMaster.GM.shipObjectList[0].transform.position + new Vector3(600, -100 + 5, 0); 57 | GameMaster.GM.player.GetComponent().playerHealth3dText.color = GameMaster.GM.fractionColors[0]; 58 | GameMaster.GM.ConstructObject(GameMaster.GM.machineGunPrefab, GameMaster.GM.player.transform.TransformPoint(10000, 0, -6000), Quaternion.Euler(0, 0, 0), "MachineGun", GameMaster.GM.weaponObjectList); 59 | GameMaster.GM.ConstructObject(GameMaster.GM.rocketLauncherPrefab, GameMaster.GM.player.transform.TransformPoint(10000, 0, -3000), Quaternion.Euler(0, 0, 0), "RocketLauncher", GameMaster.GM.weaponObjectList); 60 | GameMaster.GM.ConstructObject(GameMaster.GM.rocketLauncherMiniPrefab, GameMaster.GM.player.transform.TransformPoint(10000, 0, 0), Quaternion.Euler(0, 0, 0), "RocketLauncher", GameMaster.GM.weaponObjectList); 61 | GameMaster.GM.ConstructObject(GameMaster.GM.bombLauncherPrefab, GameMaster.GM.player.transform.TransformPoint(10000, 0, 3000), Quaternion.Euler(0, 0, 0), "BombLauncher", GameMaster.GM.weaponObjectList); 62 | 63 | if (GameMaster.GM.aiPlayerBase == true) 64 | { 65 | for (int j = 0; j < 20; j++) 66 | { 67 | GameObject newTower = GameMaster.GM.ConstructObject(GameMaster.GM.TowerGunPrefab, new Vector3(newShipObject.transform.position.x - 500 * Mathf.Cos(spawnCircleAngle2 * 3.14f / 180), 0, newShipObject.transform.position.z - 500 * Mathf.Sin(spawnCircleAngle2 * 3.14f / 180)), Quaternion.Euler(0, Random.Range(-180, 180), 0), "GunTower", GameMaster.GM.globalObjectList); 68 | newTower.GetComponent().SetFractionId(newShipObject.GetComponent().factionId); 69 | newTower.GetComponent().isVulnerable = true; 70 | newTower.GetComponent().health = 5000; 71 | newTower.GetComponent().maxHP = 5000; 72 | spawnCircleAngle2 += 360 / 20; 73 | } 74 | } 75 | } 76 | else 77 | { 78 | for (int j = 0; j < 20; j++) 79 | { 80 | GameObject newTower = GameMaster.GM.ConstructObject(GameMaster.GM.TowerGunPrefab, new Vector3(newShipObject.transform.position.x - 500 * Mathf.Cos(spawnCircleAngle2 * 3.14f / 180), 0, newShipObject.transform.position.z - 500 * Mathf.Sin(spawnCircleAngle2 * 3.14f / 180)), Quaternion.Euler(0, Random.Range(-180, 180), 0), "GunTower", GameMaster.GM.globalObjectList); 81 | newTower.GetComponent().SetFractionId(newShipObject.GetComponent().factionId); 82 | newTower.GetComponent().isVulnerable = true; 83 | newTower.GetComponent().health = 5000; 84 | newTower.GetComponent().maxHP = 5000; 85 | spawnCircleAngle2 += 360 / 20; 86 | } 87 | } 88 | 89 | spawnCircleAngle += 360 / GameMaster.GM.mainBaseCount; 90 | } 91 | } 92 | 93 | public void CreateShipPlatforms() 94 | { 95 | for (int i = 0; i < GameMaster.GM.shipObjectList.Count; i++) 96 | { 97 | GameObject newPlatformObject = GameMaster.GM.ConstructObject(GameMaster.GM.platformPrefab, GameMaster.GM.shipObjectList[i].transform.position - new Vector3(0, GameMaster.GM.shipObjectList[i].transform.position.y - 20, 0), Quaternion.Euler(0, 0, 0), "Platform", GameMaster.GM.platformObjectList); 98 | newPlatformObject.transform.SetParent(GameMaster.GM.shipObjectList[i].transform); 99 | newPlatformObject.transform.localPosition = new Vector3(0, -275, -81); 100 | GameMaster.GM.shipObjectList[i].GetComponent().EarnMoney(0); 101 | newPlatformObject.gameObject.GetComponent().healthBar.transform.localScale = new Vector3(0, 0, 0); 102 | } 103 | } 104 | 105 | public void CreateSeekers(int count) 106 | { 107 | for (int i = 0; i < GameMaster.GM.mainBaseCount; i++) 108 | for (int j = 0; j < count; j++) 109 | { 110 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.seekerPrefab, GameMaster.GM.shipObjectList[i].transform.position - new Vector3(0, GameMaster.GM.shipObjectList[i].transform.position.y, 0) + 111 | new Vector3(Random.Range(-300, 300), 0, Random.Range(-300, 300)), Quaternion.Euler(0, 0, 0), "Seeker", GameMaster.GM.globalObjectList); 112 | 113 | createdObject.GetComponent().SetFractionId(i); 114 | createdObject.GetComponent().textHP.gameObject.GetComponent().color = GameMaster.GM.fractionColors[i]; 115 | 116 | warriorPosition = createdObject.transform.position + new Vector3(0, 2, 0); 117 | GameMaster.GM.GiveWeaponToObject(warriorPosition); 118 | } 119 | } 120 | 121 | public void CreateResources(int count) 122 | { 123 | for (int i = 0; i < count; i++) 124 | { 125 | int rndNum = Random.Range(0, GameMaster.GM.detailsList.Count); 126 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.detailsList[rndNum], -100, 100, Random.Range(10, 500), Quaternion.Euler(0, 0, 0), "Follower", GameMaster.GM.globalObjectList); 127 | 128 | if (createdObject.GetComponent() == null) 129 | createdObject.AddComponent(); 130 | 131 | createdObject.GetComponent().mass = 5; 132 | createdObject.GetComponent().angularDrag = 0.05f; 133 | createdObject.GetComponent().drag = 1f; 134 | createdObject.GetComponent().AddTorque(transform.up * Random.Range(-1000, 1000)); 135 | createdObject.GetComponent().AddTorque(transform.forward * Random.Range(-1000, 1000)); 136 | createdObject.GetComponent().AddTorque(transform.right * Random.Range(-1000, 1000)); 137 | 138 | if (createdObject.GetComponent() != null && createdObject.GetComponent().convex == false) 139 | createdObject.GetComponent().convex = true; 140 | 141 | numCubes++; 142 | } 143 | } 144 | 145 | public void CreateRollerBalls(int count) 146 | { 147 | for (int i = 0; i < count; i++) 148 | { 149 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.rollerEnemyBasePrefab, -1000, 1000, Random.Range(2, 40), Quaternion.Euler(0, 0, 0), "RollerEnemyBase", GameMaster.GM.globalObjectList); 150 | createdObject.GetComponent().SetFractionId(5); 151 | } 152 | } 153 | 154 | public void CreateWeapons(int count) 155 | { 156 | for (int i = 0; i < count; i++) // Создаем оружие RocketLauncherPrefab, RocketLauncherMiniPrefab, MachineGunPrefab в рандомной позиции от 50 до 950 (вся карта) 157 | { 158 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.rocketLauncherPrefab, -1000, 1000, 4, Quaternion.Euler(0, 0, 0), "RocketLauncher", GameMaster.GM.weaponObjectList); 159 | createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.rocketLauncherMiniPrefab, -1000, 1000, 4, Quaternion.Euler(0, 0, 0), "RocketLauncher", GameMaster.GM.weaponObjectList); 160 | createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.machineGunPrefab, -1000, 1000, 4, Quaternion.Euler(0, 0, 0), "MachineGun", GameMaster.GM.weaponObjectList); 161 | } 162 | } 163 | 164 | public void CreateTroopers(int count) 165 | { 166 | for (int i = 0; i < GameMaster.GM.mainBaseCount; i++) 167 | for (int j = 0; j < count; j++) 168 | { 169 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.trooperPrefab, GameMaster.GM.shipObjectList[i].transform.position + new Vector3(Random.Range(-130, 130), -GameMaster.GM.shipObjectList[i].transform.position.y, Random.Range(-130, 130)), Quaternion.Euler(0, 0, 0), "Trooper", GameMaster.GM.unitList); 170 | 171 | createdObject.GetComponent().SetFractionId(i); 172 | createdObject.GetComponent().textHP.gameObject.GetComponent().color = GameMaster.GM.fractionColors[i]; 173 | 174 | if (createdObject.GetComponent().factionId == 0) 175 | createdObject.GetComponent().textHP.gameObject.GetComponent().text = createdObject.GetComponent().level.ToString() + " *"; 176 | 177 | warriorPosition = createdObject.transform.position + new Vector3(0, 0, 0); 178 | GameMaster.GM.GiveWeaponToObject(warriorPosition); 179 | 180 | int rnDShip = Random.Range(0, GameMaster.GM.mainBaseCount); 181 | while (rnDShip == i) 182 | rnDShip = Random.Range(0, GameMaster.GM.mainBaseCount); 183 | if (i != 0) 184 | createdObject.GetComponent().targetToChase = GameMaster.GM.shipObjectList[rnDShip]; 185 | else 186 | createdObject.GetComponent().targetToChase = GameMaster.GM.player.gameObject; 187 | } 188 | } 189 | 190 | public void CreateLightShips(int count) 191 | { 192 | for (int i = 0; i < GameMaster.GM.mainBaseCount; i++) 193 | for (int j = 0; j < count; j++) 194 | { 195 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.lightShipPrefab, GameMaster.GM.shipObjectList[i].transform.position + new Vector3(Random.Range(-130, 130), -GameMaster.GM.shipObjectList[i].transform.position.y + 3, Random.Range(-130, 130)), Quaternion.Euler(0, 0, 0), "LightShip", GameMaster.GM.unitList); 196 | 197 | //float RandomScale = Random.Range(2f, 3f); // Рандомизируем размеры пехоты 198 | //CreatedObject.transform.localScale = new Vector3(RandomScale, RandomScale, RandomScale); // Рандомизируем размеры пехоты 199 | 200 | createdObject.GetComponent().SetFractionId(i); 201 | createdObject.GetComponent().textHP.gameObject.GetComponent().color = GameMaster.GM.fractionColors[i]; 202 | 203 | if (createdObject.GetComponent().factionId == 0) 204 | createdObject.GetComponent().textHP.gameObject.GetComponent().text = createdObject.GetComponent().level.ToString() + " *"; 205 | 206 | warriorPosition = createdObject.transform.position + new Vector3(0, 2, 0); 207 | GameMaster.GM.GiveWeaponToObject(warriorPosition); 208 | int rndShip = Random.Range(0, GameMaster.GM.mainBaseCount); 209 | 210 | while (rndShip == i) 211 | rndShip = Random.Range(0, GameMaster.GM.mainBaseCount); 212 | 213 | if (i != 0) 214 | createdObject.GetComponent().targetToChase = GameMaster.GM.shipObjectList[rndShip]; 215 | else 216 | createdObject.GetComponent().targetToChase = GameMaster.GM.player.gameObject; 217 | } 218 | } 219 | 220 | public void GenerateCubes () 221 | { 222 | int rndNum = Random.Range(0, GameMaster.GM.detailsList.Count); 223 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.detailsList[rndNum], new Vector3(spawnPlatform.transform.position.x + Random.Range(-100, 100), 20, spawnPlatform.transform.position.z + Random.Range(-100, 100)), Quaternion.Euler(0, 0, 0), "Follower", GameMaster.GM.globalObjectList); 224 | 225 | if (createdObject.GetComponent() == null) 226 | createdObject.AddComponent(); 227 | 228 | createdObject.GetComponent().mass = 5; 229 | createdObject.GetComponent().angularDrag = 0.05f; 230 | createdObject.GetComponent().drag = 1f; 231 | createdObject.GetComponent().AddTorque(transform.up * Random.Range(-1000, 1000)); 232 | createdObject.GetComponent().AddTorque(transform.forward * Random.Range(-1000, 1000)); 233 | createdObject.GetComponent().AddTorque(transform.right * Random.Range(-1000, 1000)); 234 | 235 | if (createdObject.GetComponent() != null && createdObject.GetComponent().convex == false) 236 | createdObject.GetComponent().convex = true; 237 | 238 | numCubes++; 239 | } 240 | 241 | public void GenerateRollerBalls() 242 | { 243 | int rndNum = Random.Range(0, GameMaster.GM.detailsList.Count); 244 | GameObject createdObject = GameMaster.GM.ConstructObject(GameMaster.GM.rollerEnemyBasePrefab, 0, 100, Random.Range(10, 20), Quaternion.Euler(0, 0, 0), "Roller", GameMaster.GM.globalObjectList); 245 | 246 | createdObject.GetComponent().SetFractionId(5); 247 | } 248 | 249 | public static void printDeadHandler() 250 | { 251 | GameMaster.GM.playerShipHp.color = Color.red; 252 | GameMaster.GM.playerShipHp.text ="PlayerShip Destroyed"; 253 | } 254 | 255 | public void UpdateStats() 256 | { 257 | statsText.text = "Ships: " + GameObject.FindGameObjectsWithTag("Ship").Length.ToString() + "\n" + "Seekers: " + GameObject.FindGameObjectsWithTag("Seeker").Length.ToString() + "\n" + "Units: " + GameObject.FindGameObjectsWithTag("Trooper").Length.ToString() + "\n" + "Cubes: " + (GameObject.FindGameObjectsWithTag("Follower").Length + GameObject.FindGameObjectsWithTag("OwnedFollower").Length).ToString() + "\n" + "Rockets: " + GameObject.FindGameObjectsWithTag("RocketAmmo").Length.ToString() + "\n" + "Gun-Towers: " + GameObject.FindGameObjectsWithTag("TowerGun").Length.ToString() + "\n" + "Rocket-Towers: " + GameObject.FindGameObjectsWithTag("Tower").Length.ToString() + "\n"; 258 | statsText.text += "Total Objects: " + (GameObject.FindGameObjectsWithTag("Ship").Length + GameObject.FindGameObjectsWithTag("Seeker").Length + GameObject.FindGameObjectsWithTag("Trooper").Length + GameObject.FindGameObjectsWithTag("Follower").Length + GameObject.FindGameObjectsWithTag("OwnedFollower").Length + GameObject.FindGameObjectsWithTag("RocketAmmo").Length + GameObject.FindGameObjectsWithTag("TowerGun").Length + GameObject.FindGameObjectsWithTag("Tower").Length).ToString(); 259 | } 260 | } 261 | 262 | 263 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Ship.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public delegate void DeadDelegate(); 6 | 7 | public class Ship : Seeker 8 | { 9 | public event DeadDelegate shipIsDeadEvent = null; 10 | 11 | float timer; 12 | public float money; 13 | public List fractionBarracsList; 14 | public List fractionFactoryList; 15 | public List fractionTowerList; 16 | public AudioSource insufficientFunds; 17 | 18 | public override void Awake() 19 | { 20 | money = 200000 * GameMaster.GM.startMoney / 100; 21 | health = 200000; 22 | maxHP = 200000; 23 | gameObject.tag = "Ship"; 24 | countOfItemsCollected = 0; 25 | isVulnerable = true; 26 | textHP = Instantiate(GameMaster.GM.text3dDamage, transform.position + new Vector3(0, 7, 0), Quaternion.Euler(0, 0, 0)); 27 | textHP.gameObject.GetComponent().text = health.ToString(); 28 | textHP.transform.parent = transform; 29 | 30 | healthBar = Instantiate(GameMaster.GM.healthBar, transform.position + new Vector3(0, 12, 0), Quaternion.Euler(0, 0, 0)); 31 | healthBar.transform.SetParent(gameObject.transform); 32 | healthBar.transform.eulerAngles = transform.eulerAngles - new Vector3 (0,90,0); 33 | healthBarScaleMultiplier = 300; 34 | 35 | healthBar.transform.localScale = new Vector3(health / maxHP * healthBarScaleMultiplier, 10, 10); 36 | textHP.transform.localScale = new Vector3(10, 10, 10); 37 | 38 | textHP.transform.localPosition = new Vector3(0, 1000, 400); 39 | healthBar.transform.localPosition = new Vector3(0, 500, 400); 40 | 41 | if (gameObject.name == "Base") 42 | healthBar.transform.localScale = new Vector3(0, 0, 0); 43 | } 44 | 45 | public void Start() 46 | { 47 | textHP.GetComponent().color = healthBar.GetComponent().color; 48 | textHP.GetComponent().fontSize = 355; 49 | 50 | if (factionId == 0) { 51 | //money /= 10; 52 | } 53 | 54 | UpdateMoneyStats(); 55 | 56 | } 57 | 58 | public void FixedUpdate() 59 | { 60 | MoveShip(); 61 | EnemyAI(); 62 | } 63 | 64 | public void CheckForDeadShip () 65 | { 66 | if (shipIsDeadEvent != null) 67 | shipIsDeadEvent.Invoke(); 68 | } 69 | 70 | public void EnemyAI() 71 | { 72 | int rndUnit; 73 | int rndBuilding; 74 | 75 | if (GameMaster.GM.aiPlayerBase == false && factionId != 0 || GameMaster.GM.aiPlayerBase == true) 76 | { 77 | { 78 | if (fractionBarracsList.Count > 0 && CountFractionWarriors(factionId) <= GameMaster.GM.unitsCount && money > 600) 79 | { 80 | //SpendMoneyMethod spendOnTrooperDelegate = startCreatingTrooper; 81 | //SpendMoneyMethod spendOnLightShipDelegate = startCreatingLightShip; 82 | rndUnit = Random.Range(0, 100); 83 | 84 | if (rndUnit < 70) 85 | spendMoney(300, startCreatingTrooper); 86 | } 87 | 88 | if (fractionFactoryList.Count > 0 && CountFractionWarriors(factionId) <= GameMaster.GM.unitsCount && money > 600) 89 | { 90 | //SpendMoneyMethod spendOnTrooperDelegate = startCreatingTrooper; 91 | //SpendMoneyMethod spendOnLightShipDelegate = startCreatingLightShip; 92 | rndUnit = Random.Range(0, 100); 93 | 94 | if (rndUnit < 70) 95 | spendMoney(600, startCreatingLightShip); 96 | } 97 | 98 | if (fractionBarracsList.Count < 3 && money > 3000) 99 | { 100 | //SpendMoneyMethod SpendOnBarracsDelegate = startBarracsConstruction; 101 | //SpendMoneyMethod SpendOnFactoryDelegate = startFactoryConstruction; 102 | rndBuilding = Random.Range(0, 100); 103 | 104 | if (rndBuilding < 50) 105 | spendMoney(2000, startBarracsConstruction); 106 | else 107 | { 108 | spendMoney(3000, startFactoryConstruction); 109 | } 110 | } 111 | 112 | if (fractionBarracsList.Count > 0 && money > 5000 && fractionBarracsList.Count < 3) 113 | { 114 | SpendMoneyMethod SpendOnTowerDelegate = startCreatingTower; 115 | 116 | rndBuilding = Random.Range(0, 100); 117 | 118 | spendMoney(5000, SpendOnTowerDelegate); 119 | 120 | } 121 | } 122 | } 123 | } 124 | 125 | public void startBarracsConstruction() 126 | { 127 | CreateBuilding(GameMaster.GM.trooperBase, "Barracs"); 128 | } 129 | 130 | public void startFactoryConstruction() 131 | { 132 | CreateBuilding(GameMaster.GM.factoryPrefab, "Factory"); 133 | } 134 | 135 | public void startCreatingTrooper() 136 | { 137 | CreateUnit(5, GameMaster.GM.trooperPrefab, "Trooper"); 138 | } 139 | 140 | public void startCreatingLightShip() 141 | { 142 | CreateUnit(5, GameMaster.GM.lightShipPrefab, "LightShip"); 143 | } 144 | 145 | public void startCreatingTower() 146 | { 147 | CreateBuilding(GameMaster.GM.TowerPrefab, "Tower"); 148 | } 149 | 150 | public void startCreatingGunTower() 151 | { 152 | CreateBuilding(GameMaster.GM.TowerGunPrefab, "GunTower"); 153 | } 154 | 155 | public void CreateBuilding(GameObject buildingPrefabObject, string buildingName) 156 | { 157 | GameObject newBuilding = null; 158 | if (gameObject != null) 159 | { 160 | if (GameMaster.GM.aiPlayerBase == false) 161 | { 162 | if (factionId != 0) 163 | { 164 | newBuilding = GameMaster.GM.ConstructObject(buildingPrefabObject, GameMaster.GM.shipObjectList[factionId].transform.position 165 | + new Vector3(Random.Range(-500, 500), -GameMaster.GM.shipObjectList[factionId].transform.position.y, Random.Range(-500, 500)), 166 | Quaternion.Euler(0, 0, 0), buildingName, GameMaster.GM.trooperBaseList); 167 | } 168 | else 169 | { 170 | newBuilding = GameMaster.GM.ConstructObject(buildingPrefabObject, GameMaster.GM.player.TransformPoint(0, 0, 25000), 171 | Quaternion.Euler(0, 0, 0), buildingName, GameMaster.GM.trooperBaseList); 172 | } 173 | } 174 | else 175 | { 176 | newBuilding = GameMaster.GM.ConstructObject(buildingPrefabObject, GameMaster.GM.shipObjectList[factionId].transform.position 177 | + new Vector3(Random.Range(-500, 500), -GameMaster.GM.shipObjectList[factionId].transform.position.y, Random.Range(-500, 500)), 178 | Quaternion.Euler(0, 0, 0), buildingName, GameMaster.GM.trooperBaseList); 179 | } 180 | 181 | 182 | 183 | newBuilding.transform.position = new Vector3(newBuilding.transform.position.x, 0, newBuilding.transform.position.z); 184 | 185 | newBuilding.GetComponent().SetFractionId(factionId); 186 | if (newBuilding.gameObject.tag == "Barracs") 187 | fractionBarracsList.Add(newBuilding); 188 | if (newBuilding.gameObject.tag == "Factory") 189 | fractionFactoryList.Add(newBuilding); 190 | } 191 | } 192 | 193 | public void CreateUnit(int UnitCount, GameObject unitPrefab, string unitName) 194 | { 195 | if (GameMaster.GM.shipObjectList[factionId].gameObject != null) 196 | { 197 | for (int j = 0; j < UnitCount; j++) 198 | { 199 | GameObject createdObject = null; 200 | int rndBaseSpawnTrooper = Random.Range(0, fractionBarracsList.Count); 201 | int rndBaseSpawnLightShip = Random.Range(0, fractionFactoryList.Count); 202 | 203 | if (unitName == "Trooper") 204 | if (fractionBarracsList.Count > 0) 205 | if (fractionBarracsList[rndBaseSpawnTrooper].gameObject != null) 206 | { 207 | createdObject = GameMaster.GM.ConstructObject(unitPrefab, fractionBarracsList[rndBaseSpawnTrooper].transform.position + new Vector3(Random.Range(-120, 120), 0, Random.Range(-120, 120)), Quaternion.Euler(0, 0, 0), unitName, GameMaster.GM.unitList); 208 | createdObject.GetComponent().SetFractionId(factionId); 209 | Vector3 warriorPosition = createdObject.transform.position + new Vector3(0, 2, 0); 210 | GameMaster.GM.GiveWeaponToObject(warriorPosition); 211 | if (createdObject.GetComponent() != null) 212 | { 213 | createdObject.GetComponent().targetIsShip = false; 214 | 215 | if (factionId == 0 && GameMaster.GM.aiPlayerBase == false) 216 | createdObject.GetComponent().targetToChase = GameMaster.GM.player.gameObject; 217 | } 218 | 219 | //float randomScale = Random.Range(1f, 2f); // Рандомизируем размеры пехоты 220 | //createdObject.transform.localScale = new Vector3(randomScale, randomScale, randomScale); // Рандомизируем размеры пехоты 221 | 222 | createdObject.GetComponent().textHP.GetComponent().color = GameMaster.GM.fractionColors[this.factionId]; 223 | 224 | if (createdObject.GetComponent().factionId != 0) 225 | AttackPlayerWithProbability(0, createdObject); 226 | 227 | if (createdObject.GetComponent() != null) 228 | createdObject.GetComponent().targetToChaseByPlayerCommand = createdObject.GetComponent().targetToChase; 229 | } 230 | 231 | if (unitName == "LightShip") 232 | if (fractionFactoryList.Count > 0) 233 | if (fractionFactoryList[rndBaseSpawnLightShip].gameObject != null) 234 | { 235 | createdObject = GameMaster.GM.ConstructObject(unitPrefab, fractionFactoryList[rndBaseSpawnLightShip].transform.position + new Vector3(Random.Range(-80, 80), 0, Random.Range(-80, 80)), Quaternion.Euler(0, 0, 0), unitName, GameMaster.GM.unitList); 236 | 237 | createdObject.GetComponent().SetFractionId(factionId); 238 | Vector3 warriorPosition = createdObject.transform.position + new Vector3(0, 2, 0); 239 | GameMaster.GM.GiveWeaponToObject(warriorPosition); 240 | 241 | if (createdObject.GetComponent() != null) 242 | { 243 | createdObject.GetComponent().targetIsShip = false; 244 | 245 | if (factionId == 0 && GameMaster.GM.aiPlayerBase == false) 246 | createdObject.GetComponent().targetToChase = GameMaster.GM.player.gameObject; 247 | } 248 | 249 | //float randomScale = Random.Range(1f, 2f); // Рандомизируем размеры пехоты 250 | //createdObject.transform.localScale = new Vector3(randomScale, randomScale, randomScale); // Рандомизируем размеры пехоты 251 | 252 | createdObject.GetComponent().textHP.GetComponent().color = GameMaster.GM.fractionColors[this.factionId]; 253 | 254 | if (createdObject.GetComponent().factionId != 0) 255 | AttackPlayerWithProbability(GameMaster.GM.attackProbability, createdObject); 256 | 257 | if (createdObject.GetComponent() != null) 258 | createdObject.GetComponent().targetToChaseByPlayerCommand = createdObject.GetComponent().targetToChase; 259 | } 260 | } 261 | } 262 | } 263 | 264 | public int ChooseRandomTarget(List ListToSearchEnemy) 265 | { 266 | int rndTarget = factionId; 267 | 268 | while (rndTarget == factionId) 269 | rndTarget = Random.Range(0, GameMaster.GM.mainBaseCount); 270 | 271 | return rndTarget; 272 | } 273 | 274 | public void AttackPlayerWithProbability(int choosenProbability, GameObject attacker) 275 | { 276 | int rndPlayerAttack = Random.Range(0, 100); 277 | 278 | if (rndPlayerAttack < choosenProbability) 279 | { 280 | if (attacker.GetComponent() != null) 281 | attacker.GetComponent().targetToChase = GameMaster.GM.player.transform.gameObject; 282 | } 283 | } 284 | 285 | public int CountFractionWarriors(int fractionId) 286 | { 287 | int warriorsCount = 0; 288 | 289 | foreach (GameObject Warrior in GameMaster.GM.unitList) 290 | { 291 | if (Warrior != null && Warrior.GetComponent().factionId == fractionId) 292 | warriorsCount++; 293 | } 294 | 295 | return warriorsCount; 296 | } 297 | 298 | public int CountFractionBarracs(int fractionId, string barracsName) 299 | { 300 | int barracsCount = 0; 301 | 302 | if (GameMaster.GM.trooperBaseList != null) 303 | foreach (GameObject Barracs in GameMaster.GM.trooperBaseList) 304 | { 305 | if (Barracs.gameObject != null && Barracs.gameObject.name == barracsName && Barracs.GetComponent().factionId == fractionId) 306 | { 307 | barracsCount++; 308 | fractionBarracsList.Add(Barracs); 309 | } 310 | } 311 | 312 | return barracsCount; 313 | } 314 | 315 | public override void TakeDamage(float damage) 316 | { 317 | if (health > damage) 318 | { 319 | health -= damage; 320 | 321 | healthBar.transform.localScale = new Vector3(health / 200000 * healthBarScaleMultiplier, 10, 10); 322 | textHP.gameObject.GetComponent().text = GetComponent().health.ToString(); 323 | } 324 | else 325 | { 326 | if (dead == false) 327 | { 328 | CheckForDeadShip(); 329 | healthBar.transform.localScale = new Vector3(0, 0, 0); 330 | smoke = Instantiate(GameMaster.GM.smokeAfterDeath, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 331 | smoke.transform.parent = gameObject.transform; 332 | GameObject Explode = Instantiate(GameMaster.GM.enemyDestroy, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 333 | Explode.transform.localScale += new Vector3(200, 200, 200); 334 | GameObject SmokeObj = Instantiate(smoke, gameObject.transform.position + new Vector3(0, -70, 0), Quaternion.Euler(0, 0, 0)); 335 | SmokeObj.transform.localScale += new Vector3(100, 100, 100); 336 | SmokeObj.transform.parent = gameObject.transform; 337 | } 338 | 339 | dead = true; 340 | GetComponent().isKinematic = false; 341 | GetComponent().useGravity = true; 342 | totallyDead = true; 343 | GameMaster.GM.RecursiveDestroy(transform, gameObject, 3); 344 | 345 | for (int i = 0; i < GameMaster.GM.globalObjectList.Count; i++) 346 | { 347 | if (GameMaster.GM.globalObjectList[i] != null && GameMaster.GM.globalObjectList[i].gameObject.tag == "Seeker" && GameMaster.GM.globalObjectList[i].gameObject.GetComponent().factionId == factionId) 348 | { 349 | GameObject Explode = Instantiate(GameMaster.GM.globalObjectList[i].gameObject.GetComponent().deathEffect, GameMaster.GM.globalObjectList[i].gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 350 | 351 | Destroy(Explode, 2f); 352 | 353 | Destroy(GameMaster.GM.globalObjectList[i].gameObject); 354 | 355 | GameMaster.GM.globalObjectList.RemoveAt(i); 356 | } 357 | } 358 | } 359 | } 360 | 361 | public virtual void MoveShip() 362 | { 363 | timer += Time.deltaTime; 364 | 365 | if (dead == false) 366 | { 367 | transform.position += new Vector3(0, Mathf.Sin(timer * 1.5f) * 0.07f, 0); 368 | } 369 | 370 | healthBar.transform.LookAt(GameMaster.GM.player.transform.position); 371 | textHP.transform.LookAt(GameMaster.GM.player.transform.position); 372 | textHP.transform.Rotate(0, 180, 0); 373 | } 374 | 375 | public void EarnMoney (float coinsToEarn) 376 | { 377 | money += coinsToEarn; 378 | GameMaster.GM.enemyMoneyText.text = ""; 379 | 380 | UpdateMoneyStats(); 381 | for (int i = 1; i < GameMaster.GM.shipObjectList.Count; i++) 382 | { 383 | if (GameMaster.GM.shipObjectList[i] != null) 384 | GameMaster.GM.enemyMoneyText.text += 385 | "Enemy #" + i.ToString() + ": " + GameMaster.GM.shipObjectList[i].GetComponent().money.ToString() + "\n"; 386 | } 387 | } 388 | 389 | public void spendMoney(float howMuchToSpend, SpendMoneyMethod creatingMethod) 390 | { 391 | if (money >= howMuchToSpend) 392 | { 393 | money -= howMuchToSpend; 394 | creatingMethod(); 395 | } 396 | else if (factionId == 0) 397 | insufficientFunds.Play(); 398 | 399 | GameMaster.GM.enemyMoneyText.text = ""; 400 | 401 | UpdateMoneyStats(); 402 | 403 | for (int i = 1; i < GameMaster.GM.shipObjectList.Count; i++) 404 | { 405 | if (GameMaster.GM.shipObjectList[i] != null) 406 | GameMaster.GM.enemyMoneyText.text += 407 | "AI #" + i.ToString() + ": " + GameMaster.GM.shipObjectList[i].GetComponent().money.ToString() + "\n"; 408 | } 409 | } 410 | 411 | public void UpdateMoneyStats() 412 | { 413 | if (factionId == 0) 414 | { 415 | if (GameMaster.GM.aiPlayerBase == false) 416 | { 417 | //money = 0; 418 | GameMaster.GM.playerMoneyText.text = "Player: " + money.ToString(); 419 | } 420 | else 421 | { 422 | GameMaster.GM.playerMoneyText.text = "AI #0: " + money.ToString(); 423 | } 424 | } 425 | } 426 | 427 | public void OnCollisionEnter(Collision collisioninfo) 428 | { 429 | 430 | } 431 | 432 | public override void FindItemsAround(List _GlobalObjectList, List _PlatformList) 433 | { 434 | 435 | } 436 | } 437 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Weapon.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Weapon : MonoBehaviour 6 | { 7 | public Transform objectToStick; 8 | 9 | public float damageBullet; 10 | 11 | public float timer; 12 | public float reloadTime, reloadTimeForEnemy, range; 13 | public float tick; 14 | public float camX; 15 | public float camY; 16 | public float camZ; 17 | public float ownerLevel; 18 | float sprayShoot; 19 | 20 | public Vector3 weaponPositionOffset; 21 | 22 | public GameObject rocketLauncherAmmoPrefab; 23 | public GameObject createdBullet; 24 | public GameObject bulletEffectAI, bulletEffectPlayer; 25 | GameObject targetInSphere; 26 | 27 | public bool autoTarget; 28 | public bool reloadNow; 29 | public bool soundStop; 30 | public bool isProjectile; 31 | public bool isBombLauncher; 32 | public bool isRocket; 33 | public bool rotatable; 34 | public bool foundTargetToShoot; 35 | public bool playerFollowingCommand; 36 | public bool canBePickedUp; 37 | 38 | public Seeker currentSeeker; 39 | public Player currentPlayer; 40 | 41 | Vector3 randomShootPosition; 42 | 43 | public virtual void Awake() 44 | { 45 | autoTarget = false; 46 | timer = 0; 47 | reloadNow = false; 48 | soundStop = false; 49 | rotatable = true; 50 | 51 | camX = GameMaster.GM.myCamera.transform.localPosition.x; 52 | camY = GameMaster.GM.myCamera.transform.localPosition.y; 53 | camZ = GameMaster.GM.myCamera.transform.localPosition.z; 54 | } 55 | 56 | public void Start() 57 | { 58 | InvokeRepeating("CheckForEnemyInSphere", 0, 1f); 59 | 60 | timer += (float) Random.Range(0, 1000) / 1000; 61 | } 62 | 63 | public void FixedUpdate() 64 | { 65 | if (objectToStick == null) 66 | { 67 | transform.Rotate(0, -5, 0); 68 | } 69 | } 70 | 71 | public void Update() 72 | { 73 | WeaponAction(); 74 | } 75 | 76 | public void WeaponAction() 77 | { 78 | if (objectToStick != null) 79 | { 80 | ShootTarget(); 81 | } 82 | } 83 | 84 | public GameObject CheckForEnemyInSphere() 85 | { 86 | targetInSphere = null; 87 | int layerMask = 1 << 8; 88 | if (gameObject.tag == "EnemyWeapon") 89 | { 90 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, range, layerMask); 91 | for (int i = 0; i < colliders.Length; i++) 92 | { 93 | if ((colliders[i].GetComponent() != null && objectToStick != null && colliders[i].gameObject != null 94 | && colliders[i].GetComponent().factionId != objectToStick.GetComponent().factionId 95 | && currentSeeker.GetComponent().dead == false 96 | && colliders[i].GetComponent().isSimpleFollower == false 97 | && colliders[i].GetComponent().dead == false) 98 | ) 99 | { 100 | foundTargetToShoot = true; 101 | targetInSphere = colliders[i].gameObject; 102 | if (objectToStick.transform.GetComponent() != null) 103 | objectToStick.transform.GetComponent().enemyToLook = targetInSphere.gameObject; 104 | break; 105 | } 106 | } 107 | 108 | if (foundTargetToShoot == false) 109 | if (objectToStick.transform.GetComponent() != null) 110 | { 111 | objectToStick.transform.GetComponent().enemyToLook = null; 112 | } 113 | } 114 | 115 | return targetInSphere; 116 | } 117 | 118 | public virtual void ShootTarget () 119 | { 120 | if (gameObject.tag == "PlayerWeapon") 121 | { 122 | if (Input.GetMouseButton(0) && isProjectile == true && Cursor.visible == false && objectToStick.GetComponent().tacticMode == false) 123 | { 124 | if (reloadNow == false) 125 | { 126 | if (isRocket == true && gameObject == GameMaster.GM.player.GetComponent().currentWeapon.gameObject) 127 | { 128 | GameMaster.GM.shakeCamera = true; 129 | reloadNow = true; 130 | GameObject CreatedObject = GameMaster.GM.ConstructObject(Player.mainPlayer.currentWeapon.rocketLauncherAmmoPrefab, 131 | Player.mainPlayer.currentWeapon.transform.TransformPoint(0 + (float) Random.Range(-1, 1) / 6, 0 + (float) Random.Range(-1, 1) / 6, 6), Player.mainPlayer.currentWeapon.transform.rotation, 132 | "Rocket", GameMaster.GM.bulletObjectList, true); 133 | CreatedObject.GetComponent().playersBullet = true; 134 | CreatedObject.GetComponent().LaunchSound(); 135 | CreatedObject.GetComponent().weaponToStick = gameObject; 136 | CreatedObject.gameObject.GetComponent().AddRelativeForce(Random.Range(-50, 50), Random.Range(-50, 50), 0, ForceMode.Impulse); 137 | } 138 | 139 | if (isBombLauncher == true && gameObject == GameMaster.GM.player.GetComponent().currentWeapon.gameObject) 140 | { 141 | GameMaster.GM.shakeCamera = true; 142 | reloadNow = true; 143 | GameObject CreatedObject = GameMaster.GM.ConstructObject(Player.mainPlayer.currentWeapon.rocketLauncherAmmoPrefab, 144 | Player.mainPlayer.currentWeapon.transform.TransformPoint(0, 0, 1), Player.mainPlayer.currentWeapon.transform.rotation, 145 | "Bomb", GameMaster.GM.bulletObjectList); 146 | CreatedObject.GetComponent().playersBullet = true; 147 | gameObject.GetComponent().Play(); 148 | CreatedObject.GetComponent().LaunchSound(); 149 | CreatedObject.GetComponent().weaponToStick = gameObject; 150 | GameMaster.GM.player.gameObject.GetComponent().AddRelativeForce(0, -500, -800, ForceMode.Impulse); 151 | } 152 | } 153 | } 154 | 155 | if (Input.GetMouseButton(0) && isProjectile == false && Cursor.visible == false && objectToStick.GetComponent().tacticMode == false && gameObject == GameMaster.GM.player.GetComponent().currentWeapon.gameObject) // Если нажали мышь и оружие не стреляет объектами, а пулями 156 | { 157 | GameMaster.GM.myCamera.transform.localPosition = new Vector3(Random.Range(-30, 30), Random.Range(camY - 30, camY + 30), Random.Range(camZ - 30, camZ + 30)); 158 | 159 | if (reloadNow == false) 160 | { 161 | GameMaster.GM.myCamera.transform.localPosition = new Vector3(Random.Range(-30, 30), Random.Range(camY - 30, camY + 30), Random.Range(camZ - 30, camZ + 30)); 162 | reloadNow = true; 163 | gameObject.GetComponent().Play(); 164 | 165 | RaycastHit hit; 166 | 167 | Vector3 randomizedSpray = new Vector3(Random.Range(-500, 500) / 120, Random.Range(-500, 500) / 120, Random.Range(-500, 500) / 120); 168 | 169 | gameObject.transform.localPosition = randomShootPosition + randomizedSpray * 5; 170 | gameObject.transform.GetComponent().Play(); 171 | 172 | if (Physics.Raycast(transform.position + randomizedSpray, transform.forward, out hit, 2000)) 173 | if (hit.transform.tag != "Player") 174 | { 175 | GameObject BulletPlayer = Instantiate(bulletEffectPlayer, hit.point + randomizedSpray, Quaternion.LookRotation(hit.normal)); 176 | BulletPlayer.transform.GetComponent().Play(); 177 | Destroy(BulletPlayer, 2f); 178 | 179 | if (hit.rigidbody != null && hit.transform.GetComponent() == null) 180 | hit.rigidbody.AddForce(-hit.normal * 500, ForceMode.Impulse); 181 | 182 | if (hit.transform.GetComponent() != null) 183 | { 184 | hit.transform.GetComponent().whoIsDamaging = objectToStick.gameObject; 185 | 186 | if (hit.transform.tag != "Ship") 187 | hit.transform.GetComponent().TakeDamage(damageBullet * 1.5f); 188 | else 189 | hit.transform.GetComponent().TakeDamage(damageBullet / 10); 190 | } 191 | 192 | if (hit.transform.GetComponent() != null) 193 | { 194 | hit.transform.GetComponent().Explode(); 195 | } 196 | 197 | if (hit.transform.GetComponent() != null) 198 | { 199 | hit.transform.GetComponent().Explode(); 200 | } 201 | } 202 | } 203 | } 204 | 205 | timer += Time.deltaTime; 206 | 207 | if (timer > tick) 208 | { 209 | soundStop = false; 210 | reloadNow = false; 211 | tick += reloadTime; 212 | } 213 | 214 | } 215 | 216 | if (gameObject.tag == "EnemyWeapon" && isProjectile == true) 217 | { 218 | if (foundTargetToShoot == true && targetInSphere != null) 219 | { 220 | sprayShoot = Random.Range(-10, 10); 221 | 222 | if (currentSeeker.tag != "Tower") 223 | transform.LookAt(targetInSphere.transform.position); 224 | else 225 | { 226 | Quaternion lookOnLook = Quaternion.LookRotation(new Vector3(targetInSphere.transform.position.x, targetInSphere.transform.position.y - 10, targetInSphere.transform.position.z) - transform.position); 227 | transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * 8); 228 | } 229 | 230 | if (targetInSphere.tag == "Tower") 231 | { 232 | transform.LookAt(targetInSphere.transform.position + new Vector3(0, 30, 0)); 233 | } 234 | 235 | if (targetInSphere.tag == "TowerGun") 236 | { 237 | transform.LookAt(targetInSphere.transform.position + new Vector3(0, 2, 0)); 238 | } 239 | 240 | if (soundStop == false) 241 | { 242 | soundStop = true; 243 | } 244 | 245 | if (reloadNow == false && isProjectile == true) 246 | { 247 | if (isRocket == true) 248 | { 249 | reloadNow = true; 250 | if (currentSeeker.tag != "Tower") 251 | createdBullet = GameMaster.GM.ConstructObject(rocketLauncherAmmoPrefab, transform.TransformPoint(Vector3.forward * 1), transform.rotation, "Rocket", GameMaster.GM.bulletObjectList); 252 | else 253 | { 254 | createdBullet = GameMaster.GM.ConstructObject(rocketLauncherAmmoPrefab, transform.TransformPoint(new Vector3(0, 0.3f, 0.7f)) + new Vector3(sprayShoot, sprayShoot, sprayShoot), transform.rotation, "Rocket", GameMaster.GM.bulletObjectList); 255 | createdBullet.transform.localScale = new Vector3(20, 20, 20); 256 | } 257 | 258 | 259 | createdBullet.GetComponent().LaunchSound(); 260 | createdBullet.GetComponent().weaponToStick = gameObject; 261 | } 262 | 263 | if (isBombLauncher == true) 264 | { 265 | reloadNow = true; 266 | if (currentSeeker.tag != "Tower") 267 | createdBullet = GameMaster.GM.ConstructObject(rocketLauncherAmmoPrefab, transform.TransformPoint(Vector3.forward * 1), transform.rotation, "Bomb", GameMaster.GM.bulletObjectList); 268 | else 269 | createdBullet = GameMaster.GM.ConstructObject(rocketLauncherAmmoPrefab, transform.TransformPoint(new Vector3(0, 0.3f, 0.7f)) + new Vector3(sprayShoot, sprayShoot, sprayShoot), transform.rotation, "Bomb", GameMaster.GM.bulletObjectList); 270 | 271 | createdBullet.GetComponent().LaunchSound(); 272 | createdBullet.GetComponent().weaponToStick = gameObject; 273 | } 274 | } 275 | 276 | timer += Time.deltaTime; 277 | 278 | if (timer > tick) 279 | { 280 | soundStop = false; 281 | reloadNow = false; 282 | tick += reloadTimeForEnemy; 283 | } 284 | } 285 | else 286 | foundTargetToShoot = false; 287 | } 288 | 289 | if (gameObject.tag == "EnemyWeapon" && isProjectile == false) 290 | { 291 | if (foundTargetToShoot == true && targetInSphere != null) 292 | { 293 | if (targetInSphere.name == "Trooper") 294 | { 295 | transform.LookAt(targetInSphere.transform.position + new Vector3(0, 12, 0)); 296 | } 297 | else 298 | { 299 | transform.LookAt(targetInSphere.transform.position + new Vector3(0, 0, 0)); 300 | } 301 | 302 | if (objectToStick.transform.GetComponent() != null) 303 | objectToStick.transform.GetComponent().enemyToLook = targetInSphere.gameObject; 304 | 305 | if (soundStop == false) 306 | { 307 | soundStop = true; 308 | } 309 | 310 | if (reloadNow == false && isProjectile == false) 311 | { 312 | reloadNow = true; 313 | gameObject.GetComponent().Play(); 314 | gameObject.transform.GetComponent().Play(); 315 | 316 | RaycastHit hit2; 317 | 318 | if (Physics.Raycast(transform.position, transform.forward, out hit2, range, 1 << 8)) 319 | { 320 | if (hit2.transform.GetComponent() != null) 321 | hit2.transform.GetComponent().Play(); 322 | 323 | if (hit2.transform.GetComponent() != null) 324 | { 325 | GameObject BulletAI = Instantiate(bulletEffectAI, hit2.point, Quaternion.LookRotation(hit2.normal)); 326 | Destroy(BulletAI, 2f); 327 | } 328 | 329 | if (gameObject != null) 330 | if (targetInSphere.transform.GetComponent() != null && objectToStick != null && targetInSphere.transform.GetComponent().dead == false) 331 | { 332 | targetInSphere.transform.GetComponent().whoIsDamaging = objectToStick.gameObject; 333 | targetInSphere.transform.GetComponent().TakeDamage(damageBullet); 334 | } 335 | } 336 | } 337 | 338 | timer += Time.deltaTime; 339 | 340 | if (timer > tick) 341 | { 342 | soundStop = false; 343 | reloadNow = false; 344 | tick += reloadTimeForEnemy; 345 | } 346 | } 347 | else 348 | foundTargetToShoot = false; 349 | } 350 | 351 | } 352 | 353 | public virtual void OnCollisionEnter(Collision collision) 354 | { 355 | if ((collision.gameObject.tag == "Player") && (collision.gameObject.GetComponent() != null) && canBePickedUp) 356 | { 357 | collision.gameObject.GetComponent().pickup.Play(); 358 | collision.gameObject.GetComponent().playerWeaponList.Add(this); 359 | collision.gameObject.GetComponent().currentWeapon = gameObject.GetComponent(); 360 | 361 | Component[] renderer; 362 | 363 | for (int i = 0; i < collision.gameObject.GetComponent().playerWeaponList.Count; i++) 364 | { 365 | if (collision.gameObject.GetComponent().playerWeaponList[i].GetComponent() != null) 366 | collision.gameObject.GetComponent().playerWeaponList[i].GetComponent().enabled = false; 367 | 368 | if (collision.gameObject.GetComponent().playerWeaponList[i].GetComponentsInChildren() != null) 369 | { 370 | renderer = collision.gameObject.GetComponent().playerWeaponList[i].GetComponentsInChildren(); 371 | 372 | for (int j = 0; j < renderer.Length; j++) 373 | { 374 | if (renderer[j].gameObject.name == "Laser_Gun") 375 | renderer[j].GetComponent().enabled = false; 376 | } 377 | } 378 | } 379 | 380 | if (collision.gameObject.GetComponent().currentWeapon.GetComponent() != null) 381 | collision.gameObject.GetComponent().currentWeapon.GetComponent().enabled = true; 382 | 383 | if (collision.gameObject.GetComponent().currentWeapon.GetComponentsInChildren() != null) 384 | { 385 | renderer = collision.gameObject.GetComponent().currentWeapon.GetComponentsInChildren(); 386 | 387 | for (int j = 0; j < renderer.Length; j++) 388 | { 389 | if (renderer[j].gameObject.name == "Laser_Gun") 390 | renderer[j].GetComponent().enabled = true; 391 | } 392 | } 393 | 394 | gameObject.GetComponent().currentPlayer = collision.gameObject.GetComponent(); 395 | 396 | if (gameObject.GetComponent().rocketLauncherAmmoPrefab != null) 397 | gameObject.GetComponent().rocketLauncherAmmoPrefab.GetComponent().playersBullet = true; 398 | 399 | gameObject.tag = "PlayerWeapon"; 400 | gameObject.transform.SetParent(collision.transform); 401 | gameObject.transform.localPosition = weaponPositionOffset; 402 | gameObject.transform.eulerAngles = collision.gameObject.transform.eulerAngles; 403 | 404 | randomShootPosition = gameObject.transform.localPosition; 405 | 406 | if (gameObject.name == "BombLauncher") 407 | { 408 | gameObject.transform.localEulerAngles = new Vector3(-15, -5, 0); 409 | } 410 | 411 | gameObject.GetComponent().enabled = false; 412 | objectToStick = collision.gameObject.transform; 413 | } 414 | 415 | if ((collision.gameObject.tag == "Seeker" || collision.gameObject.tag == "Trooper") && (collision.gameObject.GetComponent().alreadyHaveWeapon == false) && canBePickedUp) 416 | { 417 | collision.gameObject.GetComponent().alreadyHaveWeapon = true; 418 | collision.gameObject.GetComponent().currentWeapon = gameObject.GetComponent(); 419 | gameObject.GetComponent().currentSeeker = collision.gameObject.GetComponent(); 420 | gameObject.tag = "EnemyWeapon"; 421 | gameObject.GetComponent().enabled = false; 422 | objectToStick = collision.gameObject.transform; 423 | weaponPositionOffset.Set(0, 4, 0); 424 | Destroy(gameObject.GetComponent()); 425 | 426 | if (collision.gameObject.tag == "Trooper") 427 | gameObject.transform.SetParent(collision.gameObject.GetComponent().body.transform); 428 | 429 | if (collision.gameObject.tag == "Seeker") 430 | gameObject.transform.SetParent(collision.transform); 431 | 432 | if (collision.gameObject.name == "Seeker") 433 | transform.localPosition = new Vector3(0, -30f, 0); 434 | 435 | if (collision.gameObject.name == "Trooper") 436 | { 437 | transform.localPosition = new Vector3(-0.015f, 00.001f, 0.04f); ; 438 | 439 | if (transform.GetComponent() != null) 440 | transform.GetComponent().enabled = false; 441 | 442 | if (transform.Find("Laser_Gun") != null && transform.Find("Laser_Gun").GetComponent() != null) 443 | transform.Find("Laser_Gun").GetComponent().enabled = false; 444 | } 445 | 446 | if (collision.gameObject.name == "LightShip") 447 | { 448 | transform.localPosition = new Vector3(0f, 0f, 10f); ; 449 | } 450 | } 451 | 452 | if ((collision.gameObject.tag == "EnemyShip") && (collision.gameObject.GetComponent().alreadyHaveWeapon == false)) 453 | { 454 | collision.gameObject.GetComponent().alreadyHaveWeapon = true; 455 | collision.gameObject.GetComponent().currentWeapon = gameObject.GetComponent(); 456 | gameObject.GetComponent().currentSeeker = collision.gameObject.GetComponent(); 457 | gameObject.tag = "EnemyWeapon"; 458 | gameObject.GetComponent().enabled = false; 459 | objectToStick = collision.gameObject.transform; 460 | weaponPositionOffset.Set(0, 6, 0); 461 | } 462 | } 463 | } 464 | -------------------------------------------------------------------------------- /Assets/MainStuff/Scripts/Player.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.SceneManagement; 5 | using UnityEngine.UI; 6 | 7 | public delegate void SpendMoneyMethod(); 8 | 9 | public class Player: FactionIndex 10 | { 11 | public static Player mainPlayer; 12 | 13 | public Rigidbody RB; 14 | public Weapon currentWeapon; 15 | 16 | public bool alreadyHaveWeapon; 17 | public bool reload; 18 | public bool tacticMode; 19 | public bool deadPlayer; 20 | public bool soundAlreadyPlaying; 21 | public bool targetLockedIn; 22 | public bool stopCamControls; 23 | public float timer; 24 | public float tickWeapon; 25 | public float camX, camY, camZ, cameraX, cameraY, cameraZ; 26 | public float tickBuilding; 27 | public float selectorScale; 28 | public float reloadTime = 1; 29 | 30 | public int playerCubesCount; 31 | public int playerMoney; 32 | 33 | public ParticleSystem fire; 34 | public ParticleSystem fire2; 35 | public ParticleSystem fire3; 36 | public ParticleSystem fire4; 37 | public ParticleSystem fire5; 38 | public ParticleSystem fire6; 39 | public ParticleSystem fire7; 40 | public ParticleSystem fire8; 41 | public ParticleSystem fire9; 42 | public ParticleSystem fire10; 43 | 44 | public List teamMateList; 45 | 46 | public GameObject selector; 47 | public GameObject currentShipTarget; 48 | public GameObject clickedObject; 49 | public GameObject targetUI, followUI, followUnitUI; 50 | public GameObject targetSpritePrefab; 51 | public GameObject targetToLock; 52 | public GameObject trooperBase; 53 | 54 | public AudioSource buildingInProgress; 55 | public AudioSource buildingComplete; 56 | public AudioSource insufficientFunds; 57 | public AudioSource unableBuildMore; 58 | public AudioSource missionFailed; 59 | public AudioSource playerDeath; 60 | public AudioSource damageSound; 61 | public AudioSource voice1, voice2, voice3; 62 | public AudioSource left, right, forward, backwards, up, down; 63 | public AudioSource pickup, changeWeapon; 64 | public Transform lookCube; 65 | public AudioSource buildTower; 66 | 67 | public float fx, fy, fz; 68 | public TextMesh playerHealth3dText; 69 | 70 | public bool spectatorMode; 71 | public bool isTimeToGiveCommand; 72 | 73 | public List playerWeaponList; 74 | int currentWeaponNumber; 75 | 76 | public Sprite targetSprite, followSprite, followUnitSprite; 77 | 78 | public void Start() 79 | { 80 | playerHealth3dText.text = $"HP: {health}"; 81 | playerWeaponList = new List(); 82 | currentWeaponNumber = 0; 83 | 84 | GameMaster.GM.myCamera.transform.localPosition = new Vector3(300000, 10000000, -150000); 85 | 86 | targetSprite = targetUI.GetComponent().sprite; 87 | followSprite = followUI.GetComponent().sprite; 88 | followUnitSprite = followUnitUI.GetComponent().sprite; 89 | } 90 | 91 | public override void TakeDamage(float damage) 92 | { 93 | if (isVulnerable) 94 | { 95 | if (health >= damage) 96 | { 97 | health -= damage; 98 | } 99 | else 100 | { 101 | GameMaster.GM.playerHp.color = Color.red; 102 | GameMaster.GM.playerHp.text = "GameOver"; 103 | 104 | if (deadPlayer == false) 105 | { 106 | GameObject Explode = Instantiate(GameMaster.GM.enemyDestroy, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 107 | GameObject Smoke = Instantiate(GameMaster.GM.smokeAfterDeath, gameObject.transform.position, Quaternion.Euler(0, 0, 0)); 108 | Smoke.transform.SetParent(gameObject.transform); 109 | RB.isKinematic = true; 110 | Time.timeScale = 0.3f; 111 | 112 | if (playerDeath != null) 113 | playerDeath.Play(); 114 | 115 | if (missionFailed != null) 116 | missionFailed.Play(); 117 | 118 | Invoke("GoToMainMenu", 1.0f); 119 | } 120 | 121 | deadPlayer = true; 122 | } 123 | } 124 | 125 | GameMaster.GM.playerHp.text = "PlayerHP: " + Player.mainPlayer.health.ToString(); 126 | playerHealth3dText.text = $"HP: {health}"; 127 | } 128 | 129 | public void Heal (float healpoints) 130 | { 131 | health += healpoints; 132 | GameMaster.GM.playerHp.text = "PlayerHP: " + Player.mainPlayer.health.ToString(); 133 | playerHealth3dText.text = $"HP: {health}"; 134 | } 135 | 136 | public override void Awake() 137 | { 138 | if (mainPlayer != null) 139 | GameObject.Destroy(mainPlayer); 140 | else 141 | mainPlayer = this; 142 | 143 | //DontDestroyOnLoad(this); 144 | level = 1; 145 | reload = false; 146 | alreadyHaveWeapon = false; 147 | tickWeapon = 1; 148 | timer = 0; 149 | playerCubesCount = 0; 150 | playerMoney = 0; 151 | factionId = 0; 152 | targetSpritePrefab.transform.localScale = new Vector3(2f, 2f, 2f); 153 | selector = Instantiate(GameMaster.GM.teamSelect, transform.position + new Vector3(0, 5, 0), Quaternion.Euler(0, 0, 0)); 154 | selector.transform.Rotate(90, 0, 0); 155 | selector.transform.position = new Vector3(transform.position.x, 2, transform.position.z); 156 | selectorScale = 0; 157 | selector.transform.localScale = new Vector3(0, 0, 0); 158 | tickBuilding = 0.1f; 159 | trooperBase = null; 160 | 161 | cameraX = GameMaster.GM.myCamera.transform.localPosition.x; 162 | cameraY = GameMaster.GM.myCamera.transform.localPosition.y; 163 | cameraZ = GameMaster.GM.myCamera.transform.localPosition.z; 164 | } 165 | 166 | public void Update() 167 | { 168 | // Правая кнопка мыши 169 | if (Input.GetKey(KeyCode.Mouse1)) 170 | { 171 | selectorScale += 4; 172 | selector.transform.localScale = new Vector3(selectorScale, selectorScale, selectorScale); 173 | tacticMode = true; 174 | lookCube.transform.localPosition = new Vector3(0, 4000, 3000); 175 | GameMaster.GM.myCamera.transform.localPosition = Vector3.Lerp(GameMaster.GM.myCamera.transform.localPosition, new Vector3(0, 14000, -40000),0.05f); 176 | } 177 | 178 | // Если включен тактический режим 179 | if (tacticMode == true) 180 | { 181 | RaycastHit groundDistance; ; 182 | Physics.Raycast(transform.position, transform.forward, out groundDistance, 2000); 183 | 184 | float playerHeightTerrain = Terrain.activeTerrain.SampleHeight(transform.position); 185 | float selectorDistance = Mathf.Sqrt(Mathf.Pow(groundDistance.distance, 2) - Mathf.Pow(playerHeightTerrain, 2)); 186 | selector.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z); 187 | 188 | foreach (GameObject teamMate in teamMateList) 189 | { 190 | if (teamMate != null && teamMate.GetComponent() != null && teamMate.GetComponent().teamSelectMark != null) 191 | Destroy(teamMate.GetComponent().teamSelectMark); 192 | } 193 | 194 | teamMateList.Clear(); 195 | 196 | Collider[] team = Physics.OverlapBox(selector.transform.position, new Vector3(selectorScale / 1.5f, 9999, selectorScale / 1.5f), Quaternion.identity, 1 << 8); 197 | 198 | foreach (Collider teamMate in team) 199 | if (teamMate.tag == "Trooper" && teamMate.gameObject.GetComponent().factionId == 0) 200 | { 201 | teamMateList.Add(teamMate.gameObject); 202 | teamMate.GetComponent().teamSelectMark = Instantiate(GameMaster.GM.teamMarker, teamMate.transform.position + new Vector3(0, 12, 0), Quaternion.Euler(0, 0, 0)); 203 | if (teamMate.name == "LightShip") 204 | { 205 | teamMate.GetComponent().teamSelectMark.transform.position = new Vector3(teamMate.GetComponent().transform.position.x, teamMate.GetComponent().transform.position.y - 3, teamMate.GetComponent().transform.position.z); 206 | } 207 | 208 | if (teamMate.name == "Trooper") 209 | { 210 | teamMate.GetComponent().teamSelectMark.transform.position = new Vector3(teamMate.GetComponent().transform.position.x, 0.4f, teamMate.GetComponent().transform.position.z); 211 | } 212 | 213 | teamMate.GetComponent().teamSelectMark.transform.Rotate(90, 0, 0); 214 | teamMate.GetComponent().teamSelectMark.transform.localScale = new Vector3(4, 4, 4); 215 | teamMate.GetComponent().teamSelectMark.transform.SetParent(teamMate.gameObject.transform); 216 | } 217 | 218 | CheckTacticMode(); 219 | } 220 | 221 | // Наведение на цель для оружия 222 | //if (Physics.BoxCast(GameMaster.GM.player.transform.TransformPoint(0, 0, 0), new Vector3(0, 20, 20), transform.forward, out RaycastHit hitInfo2, Quaternion.Euler(0, 0, 0), 300, 1 << 8)) 223 | //{ 224 | // if (hitInfo2.transform.gameObject != null && hitInfo2.transform.GetComponent() != null && hitInfo2.transform.GetComponent() == null && hitInfo2.transform.GetComponent().dead == false) 225 | // { 226 | // if (hitInfo2.transform.GetComponent().fractionId != 0) 227 | // { 228 | // targetLockedIn = true; 229 | // targetToLock = hitInfo2.transform.gameObject; 230 | 231 | // if (hitInfo2.transform.name == "LightShip") 232 | // targetSpritePrefab.transform.position = hitInfo2.transform.position + new Vector3(0, 0, 0); 233 | // els 234 | // targetSpritePrefab.transform.position = hitInfo2.transform.position + new Vector3(0, 3, 0); 235 | 236 | // targetSpritePrefab.transform.LookAt(Camera.main.transform.position, -Vector3.up); 237 | 238 | // if (hitInfo2.transform.GetComponent().fractionId == 0) 239 | // targetSpritePrefab.GetComponent().color = Color.green; 240 | // else 241 | // targetSpritePrefab.GetComponent().color = Color.red; 242 | // } 243 | // } 244 | // else if (hitInfo2.transform.gameObject != null && hitInfo2.transform.GetComponent() != null && hitInfo2.transform.GetComponent().dead == true) 245 | // { 246 | // targetLockedIn = false; 247 | // targetSpritePrefab.transform.position = new Vector3(0, 1000, 0); 248 | // } 249 | //} 250 | //else 251 | //{ 252 | // targetLockedIn = false; 253 | // targetSpritePrefab.transform.position = new Vector3(0, 1000, 0); 254 | //} 255 | 256 | if (spectatorMode == true) 257 | { 258 | transform.RotateAround(new Vector3(0, 0, 0), transform.up, 2f * Time.deltaTime); 259 | transform.LookAt(new Vector3(0, 0, 0)); 260 | //transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(new Vector3(-100, 0, 0)), Time.deltaTime); 261 | } 262 | 263 | Vector3 MoveSin = new Vector3(transform.position.x + Mathf.Sin(timer * 2f) * 0.03f, transform.position.y + Mathf.Sin(timer * 1f) * 0.03f, 264 | transform.position.z + Mathf.Sin(timer * 1f) * 0.03f); 265 | 266 | gameObject.GetComponent().MovePosition(MoveSin); 267 | 268 | camX = GameMaster.GM.myCamera.transform.localPosition.x; 269 | camY = GameMaster.GM.myCamera.transform.localPosition.y; 270 | camZ = GameMaster.GM.myCamera.transform.localPosition.z; 271 | 272 | if (tacticMode == false && isTimeToGiveCommand == false) 273 | { 274 | GameMaster.GM.myCamera.transform.localPosition = new Vector3(camX + Mathf.Sin(timer * fx) * 2f, camY + Mathf.Sin(timer * fy) * 1f, 275 | camZ + Mathf.Sin(timer * fz) * 2f); 276 | lookCube.transform.localPosition = new Vector3(0, 1000, 3000); 277 | 278 | float smoothTime = 0.3F; 279 | Vector3 velocity = Vector3.zero; 280 | 281 | //GameMaster.GM.myCamera.transform.localPosition = Vector3.SmoothDamp(GameMaster.GM.myCamera.transform.localPosition, new Vector3(cameraX, cameraY, cameraZ), ref velocity, smoothTime); 282 | GameMaster.GM.myCamera.transform.localPosition = Vector3.Lerp(GameMaster.GM.myCamera.transform.localPosition, new Vector3(cameraX, cameraY, cameraZ), 0.04f); 283 | } 284 | 285 | Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 50, 1 << 9); 286 | 287 | foreach (Collider hit in colliders) 288 | if (hit.tag == "Follower" && dead == false) 289 | { 290 | Vector3 normalizeDirection = (gameObject.transform.position - hit.transform.position).normalized; 291 | hit.transform.position += normalizeDirection * Time.deltaTime * hit.GetComponent().speed * 2; 292 | } 293 | 294 | timer += Time.deltaTime; 295 | 296 | waitForCommand(); 297 | 298 | if (Input.GetKey(KeyCode.LeftControl)) 299 | { 300 | Cursor.visible = true; 301 | Cursor.lockState = CursorLockMode.None; 302 | stopCamControls = true; 303 | targetUI.GetComponent().enabled = true; 304 | } 305 | 306 | if (Input.GetKey("f")) 307 | { 308 | spectatorMode = true; 309 | } 310 | 311 | if (Input.GetKeyUp("f")) 312 | { 313 | spectatorMode = false; 314 | } 315 | 316 | if (Input.GetKey("j")) 317 | { 318 | currentWeapon.GetComponent().position = gameObject.transform.TransformPoint(0, 0, 6000); 319 | currentWeapon.GetComponent().tag = "WithoutUser"; 320 | currentWeapon.transform.parent = null; 321 | currentWeapon.objectToStick = null; 322 | currentWeapon.GetComponent().tick = 0f; 323 | currentWeapon.GetComponent().timer = 0; 324 | currentWeapon.GetComponent().reloadNow = true; 325 | currentWeapon.GetComponent().soundStop = false; 326 | currentWeapon.GetComponent().enabled = true; 327 | alreadyHaveWeapon = false; 328 | } 329 | 330 | if (Input.GetKey("g")) 331 | { 332 | for (int i = 0; i < GameMaster.GM.globalObjectList.Count; i++) 333 | Destroy(GameMaster.GM.globalObjectList[i].gameObject); 334 | 335 | GameMaster.GM.globalObjectList.Clear(); 336 | } 337 | 338 | if (Input.GetKey(KeyCode.LeftShift)) 339 | { 340 | RB.AddRelativeForce(Vector3.forward * 20000); 341 | } 342 | 343 | if (Input.GetKeyUp("0")) 344 | { 345 | CallBarracsConstruction(); 346 | } 347 | 348 | if (Input.GetKeyUp("9")) 349 | { 350 | CallFactoryConstruction(); 351 | } 352 | 353 | if (Input.GetKeyUp("1")) 354 | { 355 | CallCreatingTrooper(); 356 | buildTower.Play(); 357 | } 358 | 359 | if (Input.GetKeyUp("2")) 360 | { 361 | CallCreatingLightShip(); 362 | buildTower.Play(); 363 | } 364 | 365 | if (Input.GetKeyDown("3")) 366 | { 367 | CallCreatingGunTower(); 368 | buildTower.Play(); 369 | } 370 | 371 | if (Input.GetKeyUp("4")) 372 | { 373 | CallCreatingTower(); 374 | buildTower.Play(); 375 | } 376 | 377 | if (Input.GetKey("w")) 378 | { 379 | if (forward.isPlaying == false) 380 | { 381 | forward.Play(); 382 | } 383 | } 384 | 385 | if (Input.GetKeyUp("w")) 386 | { 387 | if (forward.isPlaying == true) 388 | { 389 | IEnumerator fadeSound1 = FadeAudioSource.FadeOut(forward, 0.5f); 390 | StartCoroutine(fadeSound1); 391 | } 392 | } 393 | 394 | if (Input.GetKey("s")) 395 | { 396 | if (backwards.isPlaying == false) 397 | { 398 | backwards.Play(); 399 | } 400 | } 401 | 402 | if (Input.GetKeyUp("s")) 403 | { 404 | if (backwards.isPlaying == true) 405 | { 406 | IEnumerator fadeSound1 = FadeAudioSource.FadeOut(backwards, 0.5f); 407 | StartCoroutine(fadeSound1); 408 | } 409 | } 410 | 411 | if (Input.GetKey("d")) 412 | { 413 | if (right.isPlaying == false) 414 | { 415 | right.Play(); 416 | } 417 | } 418 | 419 | if (Input.GetKeyUp("d")) 420 | { 421 | if (right.isPlaying == true) 422 | { 423 | IEnumerator fadeSound1 = FadeAudioSource.FadeOut(right, 0.5f); 424 | StartCoroutine(fadeSound1); 425 | } 426 | } 427 | 428 | if (Input.GetKey("a")) 429 | { 430 | if (left.isPlaying == false) 431 | { 432 | left.Play(); 433 | } 434 | } 435 | 436 | if (Input.GetKeyUp("a")) 437 | { 438 | if (left.isPlaying == true) 439 | { 440 | IEnumerator fadeSound1 = FadeAudioSource.FadeOut(left, 0.5f); 441 | StartCoroutine(fadeSound1); 442 | } 443 | } 444 | 445 | if (Input.GetKey("q")) 446 | { 447 | if (down.isPlaying == false) 448 | { 449 | down.Play(); 450 | } 451 | } 452 | 453 | if (Input.GetKeyUp("q")) 454 | { 455 | if (down.isPlaying == true) 456 | { 457 | IEnumerator fadeSound1 = FadeAudioSource.FadeOut(down, 0.5f); 458 | StartCoroutine(fadeSound1); 459 | } 460 | } 461 | 462 | if (Input.GetKey("e")) 463 | { 464 | if (up.isPlaying == false) 465 | { 466 | up.Play(); 467 | } 468 | } 469 | 470 | if (Input.GetKeyUp("e")) 471 | { 472 | if (up.isPlaying == true) 473 | { 474 | IEnumerator fadeSound1 = FadeAudioSource.FadeOut(up, 0.5f); 475 | StartCoroutine(fadeSound1); 476 | } 477 | } 478 | 479 | if (Input.GetKeyDown(KeyCode.Escape)) 480 | { 481 | GoToMainMenu(); 482 | } 483 | 484 | if (Input.GetAxis("Mouse ScrollWheel") > 0) 485 | { 486 | currentWeaponNumber += 1; 487 | 488 | if (currentWeaponNumber > playerWeaponList.Count - 1) 489 | { 490 | currentWeaponNumber = 0; 491 | } 492 | } 493 | 494 | if (Input.GetAxis("Mouse ScrollWheel") < 0) 495 | { 496 | currentWeaponNumber -= 1; 497 | 498 | if (currentWeaponNumber < 0) 499 | { 500 | currentWeaponNumber = playerWeaponList.Count - 1; 501 | } 502 | } 503 | 504 | if (Input.GetAxis("Mouse ScrollWheel") != 0) 505 | { 506 | changeWeapon.Play(); 507 | 508 | if (playerWeaponList.Count > 0) 509 | { 510 | Component[] renderer; 511 | 512 | for (int i = 0; i < playerWeaponList.Count; i++) 513 | { 514 | if (playerWeaponList[i].GetComponent() != null) 515 | playerWeaponList[i].GetComponent().enabled = false; 516 | 517 | if (playerWeaponList[i].GetComponentsInChildren() != null) 518 | { 519 | renderer = playerWeaponList[i].GetComponentsInChildren(); 520 | 521 | for (int j = 0; j < renderer.Length; j++) 522 | { 523 | if (renderer[j].gameObject.name == "Laser_Gun") 524 | renderer[j].GetComponent().enabled = false; 525 | } 526 | } 527 | } 528 | 529 | currentWeapon = playerWeaponList[currentWeaponNumber]; 530 | 531 | if (currentWeapon.GetComponent() != null) 532 | currentWeapon.GetComponent().enabled = true; 533 | 534 | if (currentWeapon.GetComponentsInChildren() != null) 535 | { 536 | renderer = currentWeapon.GetComponentsInChildren(); 537 | 538 | for (int j = 0; j < renderer.Length; j++) 539 | { 540 | if (renderer[j].gameObject.name == "Laser_Gun") 541 | renderer[j].GetComponent().enabled = true; 542 | } 543 | } 544 | } 545 | } 546 | } 547 | 548 | public void CheckTacticMode() 549 | { 550 | if (Input.GetKeyUp(KeyCode.Mouse1)) 551 | { 552 | tacticMode = false; 553 | isTimeToGiveCommand = true; 554 | selector.transform.localScale = new Vector3(0, 0, 0); 555 | selectorScale = 0; 556 | } 557 | } 558 | 559 | public void waitForCommand () 560 | { 561 | if (isTimeToGiveCommand == true) 562 | { 563 | RaycastHit hit; 564 | Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 565 | if (Physics.Raycast(ray, out hit, 5000)) 566 | { 567 | if (hit.transform.GetComponent() != null || hit.transform.GetComponent() != null) 568 | { 569 | targetUI.GetComponent().enabled = true; 570 | 571 | if (hit.transform.GetComponent().factionId != 0) 572 | { 573 | targetUI.transform.localScale = new Vector3(1.3f, 1.3f, 1.3f); 574 | targetUI.GetComponent().sprite = targetSprite; 575 | targetUI.GetComponent().transform.position = Input.mousePosition; 576 | targetUI.GetComponent().color = GameMaster.GM.fractionColors[hit.transform.GetComponent().factionId]; 577 | } 578 | else 579 | { 580 | targetUI.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); 581 | targetUI.GetComponent().sprite = followUnitSprite; 582 | targetUI.GetComponent().transform.position = Input.mousePosition + new Vector3(0, 20, 0); 583 | targetUI.GetComponent().color = GameMaster.GM.fractionColors[0]; 584 | } 585 | 586 | } 587 | 588 | if (hit.transform.gameObject.GetComponent() != null) 589 | { 590 | targetUI.transform.localScale = new Vector3(0.4f, 0.5f, 0.5f); 591 | targetUI.GetComponent().sprite = followSprite; 592 | targetUI.GetComponent().transform.position = Input.mousePosition + new Vector3(0, 25, 0); 593 | targetUI.GetComponent().color = GameMaster.GM.fractionColors[0]; 594 | } 595 | } 596 | } 597 | 598 | if (Input.GetKeyUp(KeyCode.Mouse0) && isTimeToGiveCommand == true) // Левая кнопка мыши 599 | { 600 | isTimeToGiveCommand = false; 601 | targetUI.GetComponent().enabled = false; 602 | Cursor.visible = false; 603 | Cursor.lockState = CursorLockMode.Locked; 604 | selector.transform.localScale = new Vector3(0, 0, 0); 605 | RaycastHit hit2; 606 | Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition); 607 | 608 | clickedObject = null; 609 | 610 | if (Physics.Raycast(ray2, out hit2, 5000)) 611 | { 612 | if (hit2.transform.GetComponent() != null || hit2.transform.GetComponent() != null) 613 | clickedObject = hit2.transform.gameObject; 614 | 615 | foreach (GameObject teamMate in teamMateList) 616 | { 617 | if (teamMate != null) 618 | { 619 | if (teamMate.GetComponent() != null) 620 | { 621 | if (teamMate.GetComponent().currentWeapon != null) 622 | { 623 | teamMate.GetComponent().currentWeapon.GetComponent().playerFollowingCommand = true; 624 | StartCoroutine(cancelIgnoringEnemies(teamMate.GetComponent().currentWeapon.gameObject)); 625 | } 626 | 627 | teamMate.GetComponent().targetToChase = clickedObject; 628 | 629 | if (hit2.transform.GetComponent() != null) 630 | teamMate.GetComponent().pointToChase = hit2.point; 631 | else 632 | teamMate.GetComponent().pointToChase = new Vector3(0, 0, 0); 633 | 634 | teamMate.GetComponent().targetToChaseByPlayerCommand = clickedObject; 635 | teamMate.GetComponent().wait = false; 636 | teamMate.GetComponent().enemyToLook = null; 637 | } 638 | } 639 | } 640 | 641 | if (teamMateList.Count > 0) 642 | { 643 | int Rnd = Random.Range(0, 2); 644 | 645 | switch (Rnd) 646 | { 647 | case 0: 648 | voice1.Play(); 649 | break; 650 | case 1: 651 | voice2.Play(); 652 | break; 653 | } 654 | } 655 | } 656 | 657 | // Убираем метки с юнитов 658 | foreach (GameObject teamMate in teamMateList) 659 | { 660 | if (teamMate != null && teamMate.GetComponent() != null && teamMate.GetComponent().teamSelectMark != null) 661 | Destroy(teamMate.GetComponent().teamSelectMark); 662 | } 663 | 664 | GameMaster.GM.myCamera.GetComponent().fieldOfView = 45f; 665 | } 666 | 667 | if (Input.GetKeyUp(KeyCode.Mouse0)) 668 | { 669 | Cursor.visible = false; 670 | Cursor.lockState = CursorLockMode.Locked; 671 | stopCamControls = false; 672 | } 673 | 674 | } 675 | 676 | public void CallBarracsConstruction() 677 | { 678 | SpendMoneyMethod spendOnBarracsDelegate = GameMaster.GM.shipObjectList[0].GetComponent().startBarracsConstruction; 679 | GameMaster.GM.shipObjectList[0].GetComponent().spendMoney(2000, spendOnBarracsDelegate); 680 | } 681 | 682 | public void CallFactoryConstruction() 683 | { 684 | SpendMoneyMethod spendOnFactoryDelegate = GameMaster.GM.shipObjectList[0].GetComponent().startFactoryConstruction; 685 | GameMaster.GM.shipObjectList[0].GetComponent().spendMoney(3000, spendOnFactoryDelegate); 686 | } 687 | 688 | public void CallCreatingTrooper() 689 | { 690 | SpendMoneyMethod spendOnTrooperDelegate = GameMaster.GM.shipObjectList[0].GetComponent().startCreatingTrooper; 691 | GameMaster.GM.shipObjectList[0].GetComponent().spendMoney(300, spendOnTrooperDelegate); 692 | } 693 | 694 | public void CallCreatingLightShip() 695 | { 696 | SpendMoneyMethod spendOnLightShipDelegate = GameMaster.GM.shipObjectList[0].GetComponent().startCreatingLightShip; 697 | GameMaster.GM.shipObjectList[0].GetComponent().spendMoney(600, spendOnLightShipDelegate); 698 | } 699 | 700 | public void CallCreatingTower() 701 | { 702 | SpendMoneyMethod spendOnTowerDelegate = GameMaster.GM.shipObjectList[0].GetComponent().startCreatingTower; 703 | GameMaster.GM.shipObjectList[0].GetComponent().spendMoney(600, spendOnTowerDelegate); 704 | } 705 | 706 | public void CallCreatingGunTower() 707 | { 708 | SpendMoneyMethod spendOnGunTowerDelegate = GameMaster.GM.shipObjectList[0].GetComponent().startCreatingGunTower; 709 | GameMaster.GM.shipObjectList[0].GetComponent().spendMoney(600, spendOnGunTowerDelegate); 710 | } 711 | 712 | IEnumerator cancelIgnoringEnemies (GameObject weaponToControl) 713 | { 714 | yield return new WaitForSeconds(10); 715 | if (weaponToControl != null) 716 | weaponToControl.GetComponent().playerFollowingCommand = false; 717 | } 718 | 719 | public void FixedUpdate() 720 | { 721 | if (Input.GetKey("w")) 722 | { 723 | RB.AddRelativeForce(Vector3.forward * 2f, ForceMode.VelocityChange); 724 | fire.Play(); 725 | fire2.Play(); 726 | } 727 | else 728 | { 729 | fire.Stop(); 730 | fire2.Stop(); 731 | } 732 | 733 | if (Input.GetKey("s")) 734 | { 735 | RB.AddRelativeForce(-Vector3.forward * 1.5f, ForceMode.VelocityChange); 736 | fire5.Play(); 737 | fire6.Play(); 738 | } 739 | else 740 | { 741 | fire5.Stop(); 742 | fire6.Stop(); 743 | } 744 | 745 | if (Input.GetKeyUp("s")) 746 | { 747 | fire5.Stop(); 748 | fire6.Stop(); 749 | } 750 | 751 | if (Input.GetKey("d")) 752 | { 753 | RB.AddRelativeForce(Vector3.right * 1.5f, ForceMode.VelocityChange); 754 | fire3.Play(); 755 | } 756 | else 757 | { 758 | fire3.Stop(); 759 | } 760 | 761 | if (Input.GetKey("a")) 762 | { 763 | RB.AddRelativeForce(-Vector3.right * 1.5f, ForceMode.VelocityChange); 764 | fire4.Play(); 765 | } 766 | else 767 | { 768 | fire4.Stop(); 769 | } 770 | 771 | if (Input.GetKey("q")) 772 | { 773 | RB.AddRelativeForce(Vector3.up * (-1.5f), ForceMode.VelocityChange); 774 | fire7.Play(); 775 | fire8.Play(); 776 | } 777 | else 778 | { 779 | fire7.Stop(); 780 | fire8.Stop(); 781 | } 782 | 783 | if (Input.GetKey("e")) 784 | { 785 | //if (transform.position.y < 20) 786 | // if (spectatorMode == true) 787 | RB.AddRelativeForce(Vector3.up * 1.5f, ForceMode.VelocityChange); 788 | 789 | fire9.Play(); 790 | fire10.Play(); 791 | } 792 | else 793 | { 794 | fire9.Stop(); 795 | fire10.Stop(); 796 | } 797 | 798 | if (Input.GetKey("x")) 799 | { 800 | GameMaster.GM.myCamera.GetComponent().fieldOfView -= 0.8f; 801 | } 802 | 803 | if (Input.GetKey("c")) 804 | { 805 | GameMaster.GM.myCamera.GetComponent().fieldOfView = 45f; 806 | } 807 | } 808 | 809 | public void GoToMainMenu() 810 | { 811 | Time.timeScale = 1f; 812 | SceneManager.LoadScene(0, LoadSceneMode.Single); 813 | Cursor.visible = true; 814 | Cursor.lockState = CursorLockMode.None; 815 | } 816 | } 817 | --------------------------------------------------------------------------------