Arka
1
I have 3 scripts, in first i have:
- var WEAPON1AMMMO : int;
in second:
- var Tank : GameObject;
- Tank = GameObject.Find( “Tank” );
- W1AMMO = Tank.GetComponent(TankController).WEAPON1AMMMO;
and in third:
- var GUIC : GameObject
- GUIC = GameObject.Find(“GUI”);
- var Ammo: int;
- if(WeaponNumber==1)Ammo = GUIC.GetComponent(GUIController).W1AMMO;
On PC it works fine, but on android device, Ammo is always = 0. Why?
Arka
2
i have this in all scripts #pragma strict, first script:
#pragma strict
var Joystick : GameObject;
var Direction2D : Vector2;
var Direction3D : Vector3;
var CurAngle: int;
var WEAPON1AMMMO : int;//
var WEAPON2AMMMO : int;
var WEAPON3AMMMO : int;
var WEAPON4AMMMO : int;
var WEAPON1IS : boolean;
var WEAPON2IS : boolean;
var WEAPON3IS : boolean;
var WEAPON4IS : boolean;
function Start ()
{
CurAngle =0;
Joystick = GameObject.Find( "MoveJoystick" );
}
function Update ()
{
Direction2D.x = Joystick.GetComponent(MoveJoystick).gui.pixelInset.center.x - Joystick.GetComponent(MoveJoystick).guiCenter.x;
Direction2D.y = Joystick.GetComponent(MoveJoystick).gui.pixelInset.center.y - Joystick.GetComponent(MoveJoystick).guiCenter.y;
Direction3D.y=0;
Direction3D.z=Direction2D.y;
Direction3D.x=Direction2D.x;
transform.Translate (Direction3D * Time.deltaTime * 0.05,Space.World) ;
var TargetAngle = Vector2.Angle(Vector2(0,1), Vector2(Direction3D.x,Direction3D.z));
if(!((Direction3D.x==0)&&(Direction3D.z==0)))
{
if(((Direction3D.x<0)&&(Direction3D.z<0))||((Direction3D.x<0)&&(Direction3D.z>=0)))
{
TargetAngle=360 - TargetAngle;
}
//transform.rotation.eulerAngles.y = TargetAngle;
if((Mathf.Abs(TargetAngle-transform.rotation.eulerAngles.y))>10)
{
if(TargetAngle>transform.rotation.eulerAngles.y)
{
if(Mathf.Abs(TargetAngle-transform.rotation.eulerAngles.y)<180)transform.rotation.eulerAngles.y+=10;
else transform.rotation.eulerAngles.y-=10;
}
else
{
if(Mathf.Abs(TargetAngle-transform.rotation.eulerAngles.y)<180)transform.rotation.eulerAngles.y-=10;
else transform.rotation.eulerAngles.y+=10;
}
}
else transform.rotation.eulerAngles.y = TargetAngle;
}
//Debug.Log(transform.rotation.eulerAngles.y);
}
#pragma strict
var ChoosedWeapon=1;
var W1AMMO=0;
var W2AMMO=0;
var W3AMMO=0;
var W4AMMO=0;
var Weapon1 : GameObject;
var Weapon2 : GameObject;
var Weapon3 : GameObject;
var Weapon4 : GameObject;
var W1IS : boolean;
var W2IS : boolean;
var W3IS : boolean;
var W4IS : boolean;
var Tank: GameObject;
function Start ()
{
Tank = GameObject.Find( "Tank" );
W1AMMO = Tank.GetComponent(TankController).WEAPON1AMMMO;
W2AMMO = Tank.GetComponent(TankController).WEAPON2AMMMO;
W3AMMO = Tank.GetComponent(TankController).WEAPON3AMMMO;
W4AMMO = Tank.GetComponent(TankController).WEAPON4AMMMO;
ChoosedWeapon=1;
Weapon1 = GameObject.Find("WeaponField1");
Weapon2 = GameObject.Find("WeaponField2");
Weapon3 = GameObject.Find("WeaponField3");
Weapon4 = GameObject.Find("WeaponField4");
}
function Update ()
{
if(Weapon1.GetComponent(WeaponFieldController).ThisWeaponIsGonnaBe)ChoosedWeapon=1;
else if(Weapon2.GetComponent(WeaponFieldController).ThisWeaponIsGonnaBe)ChoosedWeapon=2;
else if(Weapon3.GetComponent(WeaponFieldController).ThisWeaponIsGonnaBe)ChoosedWeapon=3;
else if(Weapon4.GetComponent(WeaponFieldController).ThisWeaponIsGonnaBe)ChoosedWeapon=4;
W1AMMO = Tank.GetComponent(TankController).WEAPON1AMMMO;
W2AMMO = Tank.GetComponent(TankController).WEAPON2AMMMO;
W3AMMO = Tank.GetComponent(TankController).WEAPON3AMMMO;
W4AMMO = Tank.gameObject.GetComponent(TankController).WEAPON4AMMMO;
W1IS = Tank.GetComponent(TankController).WEAPON1IS;
W2IS = Tank.GetComponent(TankController).WEAPON2IS;
W3IS= Tank.GetComponent(TankController).WEAPON3IS;
W4IS = Tank.GetComponent(TankController).WEAPON4IS;
}
#pragma strict
@script RequireComponent( GUITexture )
var ScrWidth;
var ScrHeight;
private var gui : GUITexture;
var WeaponNumber =0;
var LastWidth=0;
var TargetingFieldWidth=0;
var Weapon1X=0;
var Weapon2X=0;
var Weapon3X=0;
var Weapon4X=0;
var MoveFieldX=0;
var MoveFieldWidth=0;
var IsTouch=0;
var ThisWeaponIsChoosed=0;
var ThisWeaponIsGonnaBe=0;
var GUIC : GameObject;
var TankHasThisWeapon: boolean;
function Start ()
{
GUIC = GameObject.Find("GUI");
var WeaponWidth = Screen.width /12;
TargetingFieldWidth = Screen.width /3;
Weapon1X = TargetingFieldWidth;
Weapon2X = Weapon1X + WeaponWidth;
Weapon3X = Weapon2X + WeaponWidth;
Weapon4X = Weapon3X + WeaponWidth;
MoveFieldX = Weapon4X + WeaponWidth;
MoveFieldWidth = Screen.width - TargetingFieldWidth - WeaponWidth*4;
gui = GetComponent( GUITexture );
gui.pixelInset.height = Screen.height /6;
gui.pixelInset.y =0;
gui.pixelInset.width= Screen.width /12;
if(WeaponNumber==1)
gui.pixelInset.x = Weapon1X;
else if(WeaponNumber==2)
gui.pixelInset.x = Weapon2X;
else if(WeaponNumber==3)
gui.pixelInset.x = Weapon3X;
else if(WeaponNumber==4)
gui.pixelInset.x = Weapon4X;
}
function Update ()
{
if(WeaponNumber==GUIC.GetComponent(GUIController).ChoosedWeapon)ThisWeaponIsChoosed=1;
else ThisWeaponIsChoosed=0;
if(ThisWeaponIsChoosed)gui.color = Color.white;
else gui.color = Color.grey;
var count = Input.touchCount;
for(var i : int = 0;i < count; i++)
{
if((gui.HitTest(Input.GetTouch(i).position))&&(!ThisWeaponIsChoosed)&&(Input.GetTouch(i).phase==TouchPhase.Began))
{
ThisWeaponIsGonnaBe=1;
}
else
{
ThisWeaponIsGonnaBe=0;
}
}
}
function OnGUI()
{
var Ammo: int;
if(WeaponNumber==1)Ammo = GUIC.GetComponent(GUIController).W1AMMO;
else if(WeaponNumber==2)Ammo = GUIC.GetComponent(GUIController).W2AMMO;
else if(WeaponNumber==3)Ammo = GUIC.GetComponent(GUIController).W3AMMO;
else if(WeaponNumber==4)Ammo = GUIC.gameObject.GetComponent(GUIController).W4AMMO;
if(WeaponNumber==1)TankHasThisWeapon=GUIC.GetComponent(GUIController).W1IS;
else if(WeaponNumber==2)TankHasThisWeapon=GUIC.GetComponent(GUIController).W2IS;
else if(WeaponNumber==3)TankHasThisWeapon=GUIC.GetComponent(GUIController).W3IS;
else if(WeaponNumber==4)TankHasThisWeapon=GUIC.GetComponent(GUIController).W4IS;
//if(TankHasThisWeapon)
GUI.Label(Rect(gui.pixelInset.x+gui.pixelInset.width/10,Screen.height-gui.pixelInset.height/3,gui.pixelInset.width,gui.pixelInset.height),Ammo.ToString());
//else GUI.Label(Rect(gui.pixelInset.x+gui.pixelInset.width/10,Screen.height-gui.pixelInset.height/3,gui.pixelInset.width,gui.pixelInset.height),"-");
//if(WeaponNumber==1)Debug.Log(TankHasThisWeapon);
}