Question by
TexByte · Aug 26, 2016 at 08:58 AM ·
android buildnot workingscript error
Scripts works on PC, not android.
Alright so I have a bowling script, that partially works on Android. By partially I mean some scripts work, while others don't at all. However when using PC it works fine.
Here is the code to the NON working scripts:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScoreKeeper : MonoBehaviour {
public List<BowlingFrame> Frames = new List<BowlingFrame>();
public int _Frame;
public int _Down;
public int _FrameBall = 0;
public int _Score;
HashSet<int> DownPins = new HashSet<int>();
// Use this for initialization
void Start () {
DownPins.Clear();
Frames.Add(new BowlingFrame(0));
}
// Update is called once per frame
void Update () {
}
int getDownPins()
{
// there's a bug here..
int down = 0;
foreach ( GameObject g in GameObject.FindGameObjectsWithTag("pin"))
{
// this means the pin isn't moving
if (g.GetComponent<Rigidbody>().velocity.magnitude < .1f)
{
Matrix4x4 m = g.transform.localToWorldMatrix;
Vector3 uv = m.MultiplyVector(Vector3.up).normalized;
// this means it's not pointing upwards
if (uv.y < .707)
{
down +=1 ;
}
continue;
}
if (g.transform.position.y < 0 || g.transform.position.z > 1 || g.transform.position.z < -1)
{
down +=1 ;
continue;
}
}
return down;
}
public void UpdateScore(object ball)
{
_Down = getDownPins();
BowlingFrame bf = Frames[Frames.Count-1].AddScore(_FrameBall, _Down);
_FrameBall += 1;
if (bf != null)
{
Frames.Add(bf);
NewFrame();
}
}
public void NewFrame()
{
_FrameBall = 0;
_Frame = Frames.Count;
DownPins.Clear();
Debug.Log("Starting frame " + _Frame.ToString());
gameObject.SendMessage("ResetFrame", SendMessageOptions.RequireReceiver);
_Score = BowlingFrame.Score(Frames);
}
}
public class BowlingFrame
{
int Score1 = 0;
int Score2 = 0;
int Carry;
public BowlingFrame (int carries)
{
Carry = carries;
}
public BowlingFrame AddScore(int ball, int score)
{
if (ball == 0)
{
Score1 = Mathf.Max (score,0);
if (score == 10)
{
return new BowlingFrame(2);
}
return null;
}
else
{
// we're still passing in the count of down pins
// so subtract score 1...
Score2 = score - Score1;
if (Score1 + Score2 == 10)
return new BowlingFrame(1);
return new BowlingFrame(0);
}
}
public static int Score (IEnumerable<BowlingFrame> frames)
{
int score = 0;
foreach(BowlingFrame f in frames)
{
score += f.Score1;
score += f.Score2;
if (f.Carry > 0) score += f.Score1;
if (f.Carry > 1) score += f.Score2;
}
return score;
}
}
GUI Displays, Score not updated(Not sure if this script is broken or not)
using UnityEngine;
using System.Collections;
public class ScoreDisplay : MonoBehaviour {
public ScoreKeeper _ScoreKeeper;
void OnGUI()
{
Rect r = new Rect(Screen.width - 320, 10, 300, 20);
GUI.Box(r, _ScoreKeeper._Score.ToString());
Rect s = new Rect(Screen.width - 320, 30, 300, 20);
string frameball = "Frame: {0} Ball:{1}";
GUI.Box(s, string.Format(frameball, _ScoreKeeper._Frame, _ScoreKeeper._FrameBall+1));
Rect q = new Rect(Screen.width - 320, 90, 300, 20);
GUI.Label(q, "Tap the screen to roll the ball");
}
}
And last but not least, This does not work either.
using UnityEngine;
using System.Collections;
public class ResetPinPosition : MonoBehaviour {
public Vector3 _Position;
public Quaternion _Rotation;
void OnEnable () {
_Position = gameObject.transform.position;
_Rotation = gameObject.transform.rotation;
}
public void ResetPin(object _ball)
{
gameObject.transform.position = _Position;
gameObject.transform.rotation = _Rotation;
gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
gameObject.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
}
}
Comment
Your answer
Follow this Question
Related Questions
can't change float value from OnTriggerEnter 1 Answer
Apk build has double size when building with Unity 2021.1.18f1 and build is not installable 0 Answers
AoT lists, and lists which I made with Bolt doesn't work on device, but fine work in Editor. 1 Answer
Animation working in Unity and PC build, but not Android 1 Answer