public void SetupUnitData() { // Reference Playground HealthSystemAttribute component HealthSystemAttribute healthSystem = GetComponent <HealthSystemAttribute>(); if (healthSystem) { healthSystem.maxHealth = (int)unitData.maxHealth; healthSystem.health = (int)unitData.health; } ModifyHealthAttribute modifyHealthAttrb = GetComponent <ModifyHealthAttribute>(); if (modifyHealthAttrb) { modifyHealthAttrb.healthChange = (int)-unitData.collisionDamage; } }
public void ShootObject() { // Check the cooldown if (Time.time >= timeOfLastSpawn + creationRate) { foreach (Transform shooterTransform in shooterPoints) { Vector2 actualBulletDirection = (relativeToRotation) ? (Vector2)(Quaternion.Euler(0, 0, shooterTransform.eulerAngles.z) * shootDirection) : shootDirection; GameObject newObject = Instantiate <GameObject>(prefabToSpawn); newObject.transform.position = shooterTransform.position; newObject.transform.eulerAngles = new Vector3(0f, 0f, Utils.Angle(actualBulletDirection)); newObject.tag = "Bullet"; if (EnableBaseDamage) { ModifyHealthAttribute modifyHealthAttrub = newObject.GetComponent <ModifyHealthAttribute>(); if (modifyHealthAttrub) { modifyHealthAttrub.healthChange = -baseDamage; } } // push the created objects, but only if they have a Rigidbody2D Rigidbody2D rigidbody2D = newObject.GetComponent <Rigidbody2D>(); if (rigidbody2D != null) { // Impulse means immediate rigidbody2D.AddForce(actualBulletDirection * shootSpeed, ForceMode2D.Impulse); // add a Bullet component if the prefab doesn't already have one, and assign the player ID BulletAttribute b = newObject.GetComponent <BulletAttribute>(); if (b == null) { b = newObject.AddComponent <BulletAttribute>(); } b.playerId = playerId; } } // Set the time we created object for cooldown reference timeOfLastSpawn = Time.time; } }