Hola estoy haciendo este script que el fondo suiga al al cetro de masa que es el target, enel editor fuciona perfecto en emuladores también, pero en dispositivos me pone los 2 unidades de textura ecima tapándome las plataformas y el coche,
using UnityEngine;
public class ScrollFondo : MonoBehaviour
{
public Renderer image;
private Transform targetFondo;
private void Start()
{
targetFondo = GameObject.FindGameObjectWithTag("Target").transform;
}
private void FixedUpdate()
{
Vector3 NuevaScroll = targetFondo.position;
NuevaScroll.x = targetFondo.position.x;
NuevaScroll.y = targetFondo.position.y;
image.material.mainTextureOffset = NuevaScroll * Time.fixedDeltaTime;
if (NuevaScroll.x >= 1.0f)
{
NuevaScroll.x = 0.0f;
}
if (NuevaScroll.y >= 1.0f)
{
NuevaScroll.y = 0.0f;
}
Vector3 NuevaPosicion = targetFondo.position;
NuevaPosicion.z = 0;
NuevaPosicion.y += 2;
transform.position = NuevaPosicion;
}
}
puede ser la "nuevaPosicion.z" que le has puesto cero...
prueba a poner que este "lejos" ...(valor positivo) ...por ejemplo 2 unidades (en la "Z")
nia este script tambiem
using UnityEngine;
public class CamaraPlayer : MonoBehaviour {
private Transform target;
private void Start()
{
target = GameObject.FindGameObjectWithTag("Target").transform;
}
private void Update()
{
Vector3 NuevaPosicion = target.position;
NuevaPosicion.z = -30;
NuevaPosicion.y += 3;
transform.position = NuevaPosicion;
}
}
using UnityEngine;
public class ScrollFondo : MonoBehaviour
{
public Renderer image;
private Transform targetFondo;
private void Start()
{
targetFondo = GameObject.FindGameObjectWithTag("Target").transform;
}
private void FixedUpdate()
{
Vector3 NuevaScroll = targetFondo.position;
NuevaScroll.x = targetFondo.position.x;
NuevaScroll.y = targetFondo.position.y;
image.material.mainTextureOffset = NuevaScroll * Time.fixedDeltaTime;
if (NuevaScroll.x >= 1.0f)
{
NuevaScroll.x = 0.0f;
}
if (NuevaScroll.y >= 1.0f)
{
NuevaScroll.y = 0.0f;
}
Vector3 NuevaPosicion = targetFondo.position;
NuevaPosicion.z = 10;
NuevaPosicion.y += 3;
transform.position = NuevaPosicion;
}
Solucionado muchas gracias.
El truco es no modificar el z del objeto, a vos solo te intesa el x e y (supongo un 2D). Podés modificarlo y ponerlo del valor que funcione a ojo (-2,+5,-7. etc) pero queda medio feo, lo lindo sería modificar directamente lo que te interesa. Un ejemplito:
float Zinicial;
public Transform target;
void Start(){
Zinicial = transform.position.z;
}
//Va Luego del update del target, asegurate en "Late"
void LateUpdate(){
m_transform.position = new Vector3(target.position.x , target.position.y, Zinicial);
}
si, esta muy bien eso, yo uso un metodo parecido, yo suelo poner porejemplo:
transform.position = new Vector3(nuevaPos.x, transform.position.y, nuevaPos.z);
en caso de querer conservar el valor "Y"
Bueno me funciona gracias por las respuestas pero lo dejo como lo tengo que ya me a dado dolor de cabeza jajajaja