- Home /
Random.Range returns number in different range.
I am trying to place objects using this script at a random position within certain coordinates, however, it seems they appear at entirely different coordaintes. All these objects are a child of another object.
using UnityEngine;
using System.Collections;
public class RandomMovement : MonoBehaviour {
public float speed;
void Start ()
{
gameObject.transform.position = new Vector3(Random.Range (-0.1F, 12.8F), Random.Range (-0.55F, 4.38F), 0);
rigidbody2D.fixedAngle = true;
}
void FixedUpdate () {
rigidbody2D.AddForce(Random.insideUnitSphere * speed);
}
}
From this question, I have no idea why you think that Random.Range() is not working. Note this code will place objects relative to the world coordinate system. The position reported in the inspector is a position relative to the object's parent.
Yup, as Robert says you've given us none of the debug information you used to arrive at your conclusion.
That seemed to be the problem, thank You. Silly me for forgetting that :) Should I delete this question? Or anwser it myself? I arrived that conclusion becase they were shifted by a few units and I thought they could be wrong because I used too many instances of Random, but only after robertbu noticed it I came to the right realization.
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Why am I getting a parsing error? 1 Answer
dont work maxdistance 0 Answers
BCE0043 unexpected token! pls help. 1 Answer