I have an object (Object 1) whose position is set to the position of another object (Object 2), but when I move object 2, It is just slightly behind. Because of the function of the two, I’m not sure if I can just set it as a child. Here’s the basic code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attach : MonoBehaviour {
public Transform aa;
void Start ()
{
aa = aa.GetComponent<Transform>();
}
// Update is called once per frame
void FixedUpdate ()
{
transform.position = aa.position;
}
}
You have to do that:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attach : MonoBehaviour {
public Transform aa;
private float aaPositionX;
private float aaPositionY;
private float thisObjectPositionX;
private float thisObjectPositionY;
void Start ()
{
aa = aa.GetComponent<Transform>();
aaPositionX = aa.position.x;
aaPositionY = aa.position.y;
thisObjectPositionX = transform.position.x;
thisObjectPositionY = transform.position.y;
}
// Update is called once per frame
void FixedUpdate ()
{
transform.position = new Vector3(thisObjectPositionX, thisObjectPositionY, 0);
}
}