void Start() { anim = GetComponent <Animator>(); attributes = GetComponent <EnemiesAttributes>(); character = int.Parse(gameObject.name); float randomStart = Random.value * 3; InvokeRepeating("WanderOrStay", randomStart, 3); InvokeRepeating("HuntForFood", randomStart, 1); InvokeRepeating("FightCreatures", randomStart, 1); InvokeRepeating("DefendOrRun", randomStart, 0.5f); InvokeRepeating("EnemyBreed", randomStart, 5); agent = gameObject.GetComponent <NavMeshAgent>(); obstacle = gameObject.GetComponent <NavMeshObstacle>(); sprite = gameObject.GetComponent <SpriteRenderer>(); species = gameObject.transform.parent.GetComponent <EnemiesGlobalAttributes>().species; globalAttributes = gameObject.transform.parent.gameObject.GetComponent <EnemiesGlobalAttributes>(); persona = globalAttributes.persona; StartCoroutine(SetAgentOffset(1)); }
void EnemyBreed() { float randomValue = Random.value; if (attributes.libido >= 200 && randomValue < 0.5) { GameObject activeCreature = GameObject.Find("Enemies" + globalAttributes.indice + "/" + character).gameObject; Vector3 childPosition = new Vector3(); Vector3 childRotation; Vector3 childScale; childPosition.x = activeCreature.transform.position.x + 7; // childPosition.z = activeCreature.transform.position.z + 7; // childRotation.x = 0; childRotation.y = 0; childRotation.z = 0; childScale.x = 5; childScale.y = 5; childScale.z = 1; GameObject creaturesNode = GameObject.Find("EnemiesCreatures/Enemies" + globalAttributes.indice + "/"); int lastCreatureName = int.Parse(creaturesNode.transform.GetChild(creaturesNode.transform.childCount - 1).name); GameObject childObject = new GameObject((lastCreatureName + 1).ToString()); SpriteRenderer spriteRenderer = childObject.AddComponent <SpriteRenderer>(); Animator childAnimator = childObject.AddComponent <Animator>(); childAnimator.runtimeAnimatorController = Resources.Load("playerSpeciesController") as RuntimeAnimatorController; childAnimator.updateMode = AnimatorUpdateMode.Normal; childAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate; childAnimator.SetInteger("movementUpgrade", attributes.movementUpgrade); childAnimator.SetInteger("perceptionUpgrade", attributes.perceptionUpgrade); childAnimator.SetInteger("combatUpgrade", Mathf.Max(attributes.attackUpgrade, attributes.deffenseUpgrade)); childObject.transform.parent = GameObject.Find("EnemiesCreatures/Enemies" + globalAttributes.indice + "/").transform; childObject.transform.rotation = Quaternion.Euler(childRotation); childObject.transform.localScale = childScale; BoxCollider childBox = childObject.AddComponent <BoxCollider>(); childBox.isTrigger = false; childBox.material = new PhysicMaterial("None"); Vector3 childBoxCenter; childBoxCenter.x = 0; childBoxCenter.y = 0; childBoxCenter.z = 0; childBox.center = childBoxCenter; Vector3 childBoxSize; childBoxSize.x = 0.9f; childBoxSize.y = 0.8f; childBoxSize.z = 4; childBox.size = childBoxSize; Rigidbody childRigidbody = childObject.AddComponent <Rigidbody>(); childRigidbody.mass = 10; childRigidbody.drag = 0; childRigidbody.useGravity = true; childRigidbody.isKinematic = false; childRigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete; childRigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ; childObject.tag = "EnemySpecies"; Terrain terrain = GameObject.Find("Terrain").GetComponent <Terrain>(); childPosition.y = terrain.SampleHeight(childPosition) + 40; childObject.transform.position = childPosition; childObject.transform.parent.gameObject.GetComponent <EnemiesGlobalAttributes>(); EnemiesAttributes childAttributes = childObject.AddComponent <EnemiesAttributes>(); childAttributes.movementUpgrade = attributes.movementUpgrade; childAttributes.perceptionUpgrade = attributes.perceptionUpgrade; childAttributes.attackUpgrade = attributes.attackUpgrade; childAttributes.deffenseUpgrade = attributes.deffenseUpgrade; NavMeshObstacle obstacleC = childObject.AddComponent <NavMeshObstacle>(); obstacleC.center = new Vector3(0f, 0f, 0f); obstacleC.size = new Vector3(1f, 1f, 4.1f); obstacleC.carving = true; obstacleC.enabled = true; NavMeshAgent agentC = childObject.AddComponent <NavMeshAgent>(); agentC.radius = 0.53f; agentC.height = 1; agentC.speed = (6.0f + childAttributes.movementUpgrade * 3) * GameConstants.movementSpeed; agentC.angularSpeed = 120; agentC.acceleration = 99; agentC.stoppingDistance = 0; agentC.autoBraking = true; agentC.avoidancePriority = 50; agentC.autoTraverseOffMeshLink = true; agentC.autoRepath = true; agentC.areaMask = 1; agentC.enabled = false; Debug.Log("Enemy newborn generated:\nIndice - " + globalAttributes.indice + "\nSpecies - " + species + ";\nPersona - " + persona.Nome + ";"); childObject.AddComponent <EnemiesAttributeUpdater>(); childObject.AddComponent <EnemiesCharacterMovement>(); childObject.AddComponent <FixRotation>(); childObject.AddComponent <EnemiesAutonomousBehavior>(); attributes.libido = 0; } }
void Start() { attributes = GetComponent <EnemiesAttributes>(); InvokeRepeating("IncreaseLibido", 0, 1); InvokeRepeating("DecreaseHungry", 0, 1); }
void Start() { rb = GetComponent <Rigidbody>(); attributes = GetComponent <EnemiesAttributes>(); spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); }