Chataigne/Assets/Script/Parralax.cs
Djalim Simaila 6a86813c8d CODE
Creation d'une zone runner
Correction de bug tel que la vie
2023-06-01 02:02:10 +02:00

25 lines
751 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Parralax : MonoBehaviour
{
private float length, startpos;
[SerializeField] private GameObject cam;
[SerializeField] private float parallaxEffect = 0;
// Start is called before the first frame update
void Start()
{
cam = GameObject.FindGameObjectWithTag("MainCamera");
startpos = transform.position.x;
length = GetComponent<SpriteRenderer>().bounds.size.x;
}
// Update is called once per frame
void FixedUpdate()
{
float dist = (cam.transform.position.x * parallaxEffect);
transform.position = new Vector3(startpos + dist, transform.position.y, transform.position.z);
}
}