-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasket.cs
38 lines (33 loc) · 1.12 KB
/
basket.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class basket : MonoBehaviour
{
public ScoreCounter scoreCounter;
// Start is called before the first frame update
void Start()
{
GameObject scoreGO = GameObject.Find("ScoreCounter");
scoreCounter = scoreGO.GetComponent<ScoreCounter>();
}
// Update is called once per frame
void Update()
{
Vector3 mousePos2D = Input.mousePosition;
mousePos2D.z = -Camera.main.transform.position.z;
Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D);
Vector3 pos = this.transform.position;
pos.x = mousePos3D.x;
this.transform.position = pos;
}
private void OnCollisionEnter(Collision collision)
{
GameObject collidingWith = collision.gameObject;
if (collidingWith.CompareTag("apple") || collidingWith.CompareTag("poisonApple"))
{
Destroy(collidingWith);
scoreCounter.score += 100;
HighScore.TRY_SET_HIGH_SCORE(scoreCounter.score);
}
}
}