WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

print the position of another object in Unity

Submitted by barnettech on Sun, 04/08/2018 - 09:29


void Update () {
var gObj = GameObject.Find("Player");
Debug.Log(gObj.transform.position);
}

Basic concept of endless scroller, not sure the code works exactly and is current, but basic concept:

using UnityEngine;
using System.Collections;

public class GroundSpawner : MonoBehaviour {

public GameObject[] prefabs;
public float spawnDistance;
private GameObject playerLastPosition;
private GameObject playerPosition;
float distanceTravelled = 0;
Vector3 lastPosition;

// Use this for initialization
void Start () {

// infinite coin spawning function, asynchronous
//StartCoroutine(SpawnGround());
playerPosition = GameObject.Find("Player");
lastPosition = playerPosition.transform.position;
}

// Update is called once per frame
void Update () {
distanceTravelled += Vector3.Distance(playerPosition.transform.position, lastPosition);
lastPosition = playerPosition.transform.position;
Debug.Log("distanceTravelled is " + distanceTravelled);

}

}