private void Start() { playerFire = player.GetComponentInChildren <playerFlammable>(); fire.Stop(); toyTime = false; currentState = new Wander(this); //stops fire and the toy state, begins wandering //Debug.Log(currentState); }
public void changeState(dragState newState) { currentState.OnExit(); //run exit function of state currentState = newState; //change state currentState.OnEnter(); //run start function of state }
void LateUpdate() { if (thisDragState == dragState.IsReleased) { thisDragState = dragState.IsReturning; if (debugMode) Debug.Log (this + " is released"); } if (thisDragState == dragState.IsReturning) { // The dragged object needs to maintain distance distanceFromCamera from the camera the entire time it is active. // Convert initialPosition from world position to 2D screen position. Vector2 position2D = cam.WorldToScreenPoint(initialPosition); //Convert to 3D again using distanceFromCamera Vector3 originOnScreen3D = cam.ScreenToWorldPoint(new Vector3 (position2D.x, position2D.y, distanceFromCamera)); //The transform is already distanceFromCamera distance from the camera, so calculate the vector that returns it to // initial position Vector3 returnVector = transform.position - originOnScreen3D; returnVector = returnVector.normalized; // shift the transform back towards initial position using the vector generated from this camera angle transform.position = transform.position - (returnVector * returnSpeed); if (debugMode) Debug.Log("Object Returning via "+ returnVector); float dist = Vector3.Distance(originOnScreen3D, transform.position); if (dist < returnRange) { thisDragState = dragState.Returned; if (debugMode) Debug.Log("Object Returned"); } } if (thisDragState == dragState.FollowingFinger) { // The dragged object must have NO COLLISION for this physics raycast to work Vector3 objectPosition = new Vector3 (0,0,0); objectPosition.x = TouchManager.Instance.fingerRecordedPosition.x; objectPosition.y = TouchManager.Instance.fingerRecordedPosition.y; objectPosition.z = distanceFromCamera; RaycastHit hit; Ray ray = cam.ScreenPointToRay( new Vector3 (objectPosition.x, objectPosition.y, 0 ) ); if ( Physics.Raycast ( ray, out hit) ) { if (debugMode) Debug.Log("Ray Cast Hit Object on Object"); // Is this object a collision object? if (hit.collider != null) { Collider target = hit.collider; GameObjectMode targetMode; Debug.Log(target); targetMode = target.GetComponent<GameObjectMode>(); if (targetMode) { if (targetMode.gameObjectMode == GameObjectMode.ModeList.DragObjectTarget) { thisDragState = dragState.Collected; if (debugMode) Debug.Log("Object Collected"); } } } } transform.position = cam.ScreenToWorldPoint(objectPosition); Vector2 position2D = cam.WorldToScreenPoint(destinationPosition); Vector3 destinationOnScreen3D = cam.ScreenToWorldPoint(new Vector3 (position2D.x, position2D.y, distanceFromCamera)); if (debugMode) Debug.Log("Object Dragged"); } }