I have a script which sets the position of a player object(a ball) to a point which is specifyed by an other object.
using UnityEngine;
using System.Collections;
public class GameBuilder : MonoBehaviour {
private int loadLevel=0;
public GameObject player, DCamera;
public GameObject[] level;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (loadLevel ==0) {
Debug.Log ("No Level to prepare");
} else {
player.GetComponent<Rigidbody>().constraints=RigidbodyConstraints.None;
player.GetComponent<Rigidbody>().position= new Vector3(level[loadLevel-1].transform.position.x,level[loadLevel-1].transform.position.y+0.35f,level[loadLevel-1].transform.position.z); //This sets the position of the player to origin of the loaded level
Debug.Log(new Vector3(level[loadLevel-1].transform.position.x,level[loadLevel-1].transform.position.y+0.35f,level[loadLevel-1].transform.position.z));
Debug.Log(player.GetComponent<Rigidbody>().velocity);
level [loadLevel-1].gameObject.SetActive (true);
loadLevel=0;
}
}
public void getLevel(int Level){
loadLevel = Level;
Debug.Log ("Load Level " + (loadLevel - 1));
}
public void UnloadLevel(){
for (int i=0; i<level.Length; i++) {
level *.gameObject.SetActive (false);*
* }*
* DCamera.gameObject.SetActive (true);*
* }*
*}*
*```*
*The origin of the level is -40,20,30 and the debug log shows this values too. So it is set to this position. I checked the velocity with the line below it but it's everytime 0,0,0 so the player doesn't move. At the position -40,20,30 is an object on which the ball should lie after the code is executed. But the ball is some units away form this object.*
*I can't find out where i have made the issue. Thanks everybody who wants to help me! I don't now what I should do without you ;)*
*Note: In another level the ball is at the correct position.*
*Note2: After the first frame the ball is set to -40,20,30 the position is -39.2,20.4,30 .*