Scriptum/Assets/Scripts/CamerFollow.cs
Alicja 5a5fa8a04a Minor changes
(cherry picked from commit 8e504d04364c0983e67fcccfa0eb09af2949002f)
2023-01-07 20:24:54 +01:00

87 lines
2.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamerFollow : MonoBehaviour
{
private Transform playerTransform;
private float xx;
private float yy;
public int drunk;
public float max;
public float duration;
public float speed = 10.0f;
public Vector3 temp;
// Start is called before the first frame update
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
PlayerPrefs.SetInt("drunk", 0);
}
void LateUpdate()
{
speed = 3f;
max = 0.8f;
duration += Time.deltaTime;
drunk = PlayerPrefs.GetInt("drunk");
if(drunk == 1)
{
if(duration >= max)
{
temp = transform.position;
xx = Random.Range(-3.0f, 3.0f);
yy = Random.Range(-3.0f, 3.0f);
temp.x = playerTransform.position.x + xx;
temp.y = playerTransform.position.y + yy;
duration = 0f;
}
transform.position = Vector3.MoveTowards(transform.position, temp, speed * Time.deltaTime);
if(transform.position.x == temp.x && transform.position.y == temp.y)
{
xx = Random.Range(-4.0f, 4.0f);
yy = Random.Range(-4.0f, 4.0f);
temp.x = playerTransform.position.x + xx;
temp.y = playerTransform.position.y + yy;
transform.position = Vector3.MoveTowards(transform.position, temp, speed * Time.deltaTime);
}
}
else if(drunk == 2)
{
temp.x = playerTransform.position.x;
temp.y = playerTransform.position.y;
transform.position = Vector3.MoveTowards(transform.position, temp, speed * Time.deltaTime);
if(playerTransform.position.x == transform.position.x && playerTransform.position.y == transform.position.y)
{
PlayerPrefs.SetInt("drunk", 0);
}
}
else
{
// we store current camera's position here
Vector3 temp = transform.position;
temp.x = playerTransform.position.x;
temp.y = playerTransform.position.y;
transform.position = temp;
}
}
public void Drink()
{
PlayerPrefs.SetInt("drunk", 1);
StartCoroutine(SoberUp());
}
public IEnumerator SoberUp()
{
yield return new WaitForSecondsRealtime(10);
PlayerPrefs.SetInt("drunk", 2);
}
}