I need some help with coding this idea: "For each Target destroyed, increase the Gunner's speed by (speed variable)". The idea is that the Gunner is automatically moving, and I want it to become more frantic with each target hit.
Here's the relevant code I have so far:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
void Update () {
Gunner_Move ();
}
//gives me the error "Assets/_Scripts/MovementPathScript.cs(60,83): error CS0200: Property or indexer `System.Array.Length' cannot be assigned to (it is read only)"
void Gunner_Move(){
if (GameObject.FindGameObjectsWithTag ("BulletProgressionObject").Length -= 1)
Gunner_SpeedIncrease ();
}
void Gunner_SpeedIncrease(){ //behavior that I'm not sure how to make }
//for the bullets colliding with target's parent object
void OnTriggerEnter(Collider other){
if (other.gameObject.CompareTag ("BulletProgressionObject"))
Destroy (other.gameObject);
I think it's a foreach loop, but the issue I'm having is properly implementing it. Any suggestions or referrals would be greatly appreciated.
GameObject.FindGameObjectsWithTag ("BulletProgressionObject").Length -= 1
means "decrease the array length by one" which obviously doesn't make sense because 1. array lengths are read-only, 2. it's a temporary array generated on-the-fly byFindGameObjectsWithTag
and 3. it's in an if-condition and assignments in if-conditions are not allowed. What do you really want to do in that line? What's aBulletProgressionObject
anyway? \$\endgroup\$Gunner_SpeedIncrease
is calledGunner_SetSpeed
and takes a number as an argument. \$\endgroup\$