- Home /
Question by
verschurengiovanni · Jan 30 at 05:10 PM ·
scripting problem
calculations are different in final build
Hello,
So I'm having some trouble, in the editor it all goes as intended but once I build and run it the calculations of the "progress" are different and inaccurate. It jumps from "oblique" to "straight" even when it doesn't have to.
I'm not sure what the issue and I hope someone can help me
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SchuinNew : MonoBehaviour
{
public KeyCode increaseKey;
public KeyCode decreaseKey;
public KoppieKoppie koppieKoppie;
public Text progressText;
// public AudioSource liftup;
// public AudioSource liftdown;
public float progress;
private HingeJoint joint;
public float richting;
private float lastAnimation = 0;
private float rotation;
// Animations
// public Animator knop;
void Start()
{
joint = GetComponent<HingeJoint>();
}
void Update()
{
float richting = 1;
var motor = joint.motor;
progress = transform.eulerAngles.x / joint.limits.max;
if (Input.GetKey(increaseKey) && koppieKoppie.progress >= 1.0f)
{
motor.targetVelocity = richting = 3.5f;
richting = 1;
// lastAnimation = Time.time
// liftup.Play();
}
else if (Input.GetKey(decreaseKey))
{
motor.targetVelocity = richting = -2.25f;
richting = -1;
}
joint.motor = motor;
var realProgress = transform.eulerAngles.x / joint.limits.max;
progressText.text = realProgress < .02 ? "Straight" : "Oblique";
// realProgress >= 0.02 ? "Oblique" + realProgress.ToString("0") + "%" : "Straight";
// progressText.text = realProgress ? "straight" : "oblique";
}
public void Omhoog()
{
var motor = joint.motor;
float richting = 1;
if (koppieKoppie.progress >= 1.0f && (lastAnimation == 0 || Time.time - lastAnimation > 3))
{
motor.targetVelocity = richting = 3.5f;
richting = 1;
lastAnimation = Time.time;
}
joint.motor = motor;
}
public void Omlaag()
{
var motor = joint.motor;
if (lastAnimation == 0 || Time.time - lastAnimation > 3)
{
motor.targetVelocity = richting = -2.25f;
lastAnimation = Time.time;
// liftdown.Play();
}
joint.motor = motor;
}
}
Comment
Your answer
Follow this Question
Related Questions
Ways to make OnMouseDown (or a single script) differentiate between different colliders/sprites 1 Answer
c# - List with multiple types - Trading Engine - Stock Simulator 2 Answers
variable not being changed outside of a method. [C#] 3 Answers
Trigger Sound more than Once 0 Answers
Setting a random animation frame from multiple animations 0 Answers