-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeedController.cs
More file actions
108 lines (73 loc) · 3.33 KB
/
SeedController.cs
File metadata and controls
108 lines (73 loc) · 3.33 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// This script is attached to the seed game object
// This script is using the UnityEngine.UI class
// This script is the start of our state machine, see below.
// This script eventually would handle displaying instructional text to players when they get close enough to game objects
// This script also handles when the raycast of the seed hits the dirt hole's game object's collider...
// The seed is deparented from the player's hand
// The seed's gravity is turned on, its X and Z position and rotation is frozen, and it's given a mass of 3
//STATE CHANGES
//if state = 0
//Let player 1 drop seed in hole, state == 1 (state++)
//if state = 1
//let player 2 pour water, state == 2 (state++)
//if state = 2
//let tree grow, state == 3 (state++)
public class dropSeed_final : MonoBehaviour {
public Rigidbody seedRigidBody_final;
public GameObject tree_final;
public int state_final = 0;
//public Text PlantSeedText;
public GameObject handCollider;
public Transform handColliderPosition;
public float distanceToSeed;
//public GameObject WangariAudioPlayer;
//AudioSource WangariAudio;
private void Start()
{
seedRigidBody_final = GetComponent<Rigidbody>();
handCollider = GameObject.FindWithTag("hand");
handColliderPosition = handCollider.GetComponent<Transform>();
//PlantSeedText = PlantSeedText.GetComponent<Text>();
//WangariAudio = WangariAudio.GetComponent<AudioSource>();
}
void Update () {
RaycastHit hit;
Ray rayDirection = new Ray(transform.position, Vector3.down);
Debug.DrawRay(transform.position, Vector3.down);
//PlantSeedText.enabled = false;
//PlantSeedText.gameObject.SetActive(false);
//WangariAudio.Play();
if (state_final == 0) {
Debug.Log("did it get past state change 0?");
//if the player is close enough to the seed
//show the text
// distanceToSeed = Vector3.Distance(handColliderPosition.position, transform.position);
//if (distanceToSeed < 3f) {
// Debug.Log("near seed");
// PlantSeedText.gameObject.SetActive(true);
//PlantSeedText.enabled = true;
// }
if (Physics.Raycast(rayDirection, out hit))
{
if (hit.collider.tag == "hole_final")
{
Debug.Log("deparent seed from hand");
transform.parent = null;
Debug.Log(transform.parent);
seedRigidBody_final.isKinematic = false;
seedRigidBody_final.useGravity = true;
seedRigidBody_final.constraints = RigidbodyConstraints.FreezePositionX;
seedRigidBody_final.constraints = RigidbodyConstraints.FreezePositionZ;
seedRigidBody_final.constraints = RigidbodyConstraints.FreezeRotation;
seedRigidBody_final.mass = 3f;
state_final++;
}
}
}
Debug.Log("rendered obj state = " + state_final);
}
}