Scriptum/Assets/Scripts/CamerFollow.cs

86 lines
2.6 KiB
C#
Raw Normal View History

2022-03-24 22:50:10 +01:00
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;
2022-03-24 22:50:10 +01:00
// Start is called before the first frame update
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
}
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);
}
2022-03-24 22:50:10 +01:00
}
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);
2022-03-24 22:50:10 +01:00
}
}