script not workig
using UnityEngine; using System.Collections;
public class Weaponchanging : MonoBehaviour { public Component[] weapons;
void SwitchWeapon(int index)
{
for (int i=0; i < weapons.Length; i++) // Using weapons.Length instead of other var.
{
if (i == index)
weapons[i].gameObject.GetComponent<RTCTankGunController> ().enabled = true;
else
weapons[i].gameObject.GetComponent<RTCTankGunController> ().enabled = false;
}
}
}
the script was supposed to switch between weapons (missile and a deck gun for a warship) and what is was to do to switch was to disable the firing scripts but it didn't
I know nothing about coding (had some one else help me). looked up ways to fix it ( didn't work). so plz help
I don't know if you already read what i wrote in the other question i answered already, you might have missed a bracket at the end, thats why you got the error i believe!
Edit, also i think you don't need to use gameObject. So it is :
weapons[i].GetComponent<RTCTankGunController> ().enabled = false;
What are the weapons? You say they are:
public Component[] weapons;
If they are gameobjects declare the array like:
public GameObject[] weapons;
Your answer
Follow this Question
Related Questions
I need help picking up and dropping weapons 0 Answers
Problem with a ship controller script 1 Answer
Switching Weapon Script 2 Answers
Issues Cycling Through Weapons-C# 2 Answers
An object reference is required to access non-static member 2 Answers