- Home /
[Beginner] Using Random.Range in initial game object position
I would like a game object to essentially spawn in with a random y value initially, I'm getting an error that states that it can't "convert the double expression to type float." None of my ideas of what's going on have worked, and I can't find the solution with the Scripting API. There's probably a really obvious error, can anybody help?
using UnityEngine; using System.Collections;
public class Upward : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 AntiGravity;
float RandomInt = Random.Range(-0.755f, 0.755f);
// Use this for initialization
void Start () {
transform.position = new Vector3(RandomInt,-3.4,-1.0);
}
// Update is called once per frame
void Update () {
if (transform.position.y <= 3.35) {
velocity -= AntiGravity * Time.deltaTime;
transform.position -= velocity * Time.deltaTime;
}
}
}
Comment
Best Answer
Answer by SirCrazyNugget · Jul 14, 2015 at 12:04 AM
place an f after the numerical value to cast literals as floats (d)s for doubles which is the default.
1 (int) 1.5 (double) 1.5f (float) 1.5d (double)