-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.cs
More file actions
50 lines (42 loc) · 1.69 KB
/
Copy pathCustomer.cs
File metadata and controls
50 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Customer : MonoBehaviour
{
public SpriteRenderer spriteRenderer;
public int happiness;
public Sprite[] happinessLevel;
public float timeSinceSpawned;
CurrencyManager currencyScript;
DayManager dayScript;
CustomerManager customerManagerScript;
// Start is called before the first frame update
void Start()
{
happiness = Random.Range(3, 4);
timeSinceSpawned = 50000;
spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
currencyScript = GameObject.FindGameObjectWithTag("GameManager").GetComponent<CurrencyManager>();
dayScript = GameObject.FindGameObjectWithTag("GameManager").GetComponent<DayManager>();
customerManagerScript = GameObject.FindGameObjectWithTag("GameManager").GetComponent<CustomerManager>();
}
// Update is called once per frame
void Update()
{
if(timeSinceSpawned > 0) timeSinceSpawned--;
int sadify = Random.Range(0, dayScript.happinessDecreaseRate);
if (sadify == 2) happiness--;
if (happiness >= 9) finishedHappyCustomer();
if (happiness <= 0) finishedSadCustomer();
if (happiness >= 0 && happiness <= 9) spriteRenderer.sprite = happinessLevel[happiness];
}
void finishedHappyCustomer() {
currencyScript.laughsCurrency = currencyScript.laughsCurrency + 1 + (int) Mathf.Floor(timeSinceSpawned/10000);
customerManagerScript.customersExited++;
Destroy(gameObject);
}
void finishedSadCustomer() {
dayScript.gameLose();
Destroy(gameObject);
}
}