public void startPurchaseProcess() { state = DraggingState.DraggingValid; completed = false; beginClick = false; GetComponent <OutlineComponent>().Enable(); }
void Start() { gravity = Physics.gravity * gravityModifier; meleeSwipe = meleeWeapon.GetComponent <Animator>(); playerCollider = GetComponent <CapsuleCollider>(); controller = GetComponent <CharacterController>(); startingHeight = transform.position.y; currentState = DraggingState.NONE; //ifFallen = GameObject.Find("BottomlessPit_Half").GetComponent<BottomlessPit>(); }
// Reset all variables upon release of the interact key void InteractKeyClear() { if (Input.GetButtonUp("Interact")) { medkitScavengeTimer = 2f; medvialPressed = false; keyHoldTime = 0f; spinWheelTimer = 0f; currentState = DraggingState.NONE; box = null; chargingType = null; } }
void Start() { gravity = Physics.gravity * gravityModifier; meleeSwipe = meleeWeapon.GetComponent <Animator>(); playerCollider = GetComponent <CapsuleCollider>(); controller = GetComponent <CharacterController>(); spinWheel = GameObject.FindGameObjectWithTag("SpinWheel").GetComponent <SpinWheel>(); aiFollower = GameObject.Find("AIFollow").GetComponent <AITeleport>(); startingHeight = transform.position.y; fallAmount = startingHeight + 5.0f; currentState = DraggingState.NONE; medkitScavengeTimer = medvialScavengeMaxHoldTime; }
public void DoneDragging() { //we'll find the store object real quick, very nice to use this instead of storing a reference, although technically inefficient. //okay with doing this for singleton objects like store Store gameStore = FindObjectOfType <Store> (); if (completed) { gameStore.setSelectedItem(this.gameObject); if (spawnPoint.IsOpen()) { state = DraggingState.DroppedValid; spawnPoint.AddItem(this.gameObject); } else { state = DraggingState.DroppedInvalid; } } else { //all the conditions for spawning it, if none are met, we'll just poof the object if (spawnPoint == null || !spawnPoint.IsOpen() || !gameStore.purchase(GetComponent <Item>())) { //poof method to be filled in with whatever effect we want on poofing the object state = DraggingState.DroppedInvalid; } else { //okay its go time, make it legit, put a ring on it, etc. if (costText) { GetComponentInChildren <TextDisplay>().Remove(costText); costText = null; } //no more ghost SetGhost(false); //final method to lock our object into the cell spawnPoint.AddItem(this.gameObject); gameStore.setSelectedItem(this.gameObject); state = DraggingState.DroppedValid; completed = true; } } }
//on mouse down, we'll instantiate our object and set it inactive until we drag the mouse off public void OnMouseDown() { Store gameStore = FindObjectOfType <Store> (); if (state == DraggingState.DroppedValid) { gameStore.setSelectedItem(this.gameObject); } else { gameStore.setSelectedItem(null); } state = DraggingState.DraggingValid; if (spawnPoint) { spawnPoint.AddItem(null); } GetComponent <OutlineComponent>().Enable(); beginClick = true; }
//updated with on trigger stay void OnTriggerStay(Collider other) { #region Block Dragging if (currentState == DraggingState.NONE) { if (other.name == "TopCollider" && Input.GetButton("Interact") || other.name == "BottomCollider" && Input.GetButton("Interact")) { box = other.transform.parent.gameObject; relativePosition = box.transform.position - transform.position; if (relativePosition.magnitude < 2.0f) { relativePosition.Normalize(); relativePosition *= 2.0f; } currentState = DraggingState.VERTICAL; } else if (other.name == "LeftCollider" && Input.GetButton("Interact") || other.name == "RightCollider" && Input.GetButton("Interact")) { box = other.transform.parent.gameObject; relativePosition = box.transform.position - transform.position; if (relativePosition.magnitude < 2.0f) { relativePosition.Normalize(); relativePosition *= 2.0f; } currentState = DraggingState.HORIZONTAL; } } #endregion #region Enemy //execution of enemy if (other.tag == "Enemy") { bool enemyDeadCheck = other.GetComponent <TrooperBehaviour>().xIsDownedX; if (other.tag == "Enemy" && Input.GetButtonDown("Interact") && enemyDeadCheck == true) { other.GetComponent <TrooperBehaviour>().xIsDeadX = true; } } #endregion #region Powercell & Door // Powercell pickup if (other.tag == "PowerCell" && Input.GetButtonDown("Interact")) { if (storedPowerCell >= maxPowerCell) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score storedPowerCell++; //delete the power cell Destroy(other.gameObject); } } // Door open -- this requires the panel object to have the tag 'Panel' if (other.tag == "Panel" && Input.GetButtonDown("Interact")) { //if the player has 1 or more power cells and the panel has not been activated before if (storedPowerCell >= 1 && !other.GetComponent <Panel>().xActivatedX) // panel activatd = false { //open the door storedPowerCell--; //play sound effect of door opening //destroy the door other.GetComponent <Panel>().xActivatedX = true; } else { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } #endregion #region Health & Scavenge // Medkit scavenge if (other.tag == "Health" && Input.GetButton("Interact")) { chargingType = "Health"; medkitScavengeTimer -= Time.deltaTime; int medvialAmount = 0; int healthAmount = other.gameObject.GetComponent <HealthPickup>().healthRestoreAmount; // Give amount of medvials depending on health pickup switch (healthAmount) { case 2: medvialAmount = 1; break; case 6: medvialAmount = 2; break; case 10: medvialAmount = 3; break; default: break; } if (storedMedvial >= maxMedvial) { //play sound of --NO--, DO NOT ADD to SCORE } else { // Update the score if (medkitScavengeTimer <= 0) { storedMedvial += medvialAmount; healthPickedUp = true; if (storedMedvial > maxMedvial) { storedMedvial = maxMedvial; } Destroy(other.gameObject); } if (healthPickedUp) { healthPickedUp = false; medkitScavengeTimer = medvialScavengeMaxHoldTime; } } } // Health interact if (other.tag == "Health" && Input.GetButtonUp("Interact") && keyHoldTime < medvialPressTime) { //if the player has less than max health if (currentHealth < maxHealth) { //sets up the amount to heal int healthGained = other.GetComponent <HealthPickup>().healthRestoreAmount; //heal the player currentHealth = currentHealth + healthGained; //if player gains more than max health if (currentHealth > maxHealth) { //current health gets set to max health currentHealth = maxHealth; } //play sound effect of healing //destroy the door Destroy(other.gameObject); } else { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } // Health Station if (other.gameObject.tag == "HealthStation" && Input.GetButtonDown("Interact") /*|| healthPickedUp*/) { if (storedMedvial >= maxMedvial || (!other.GetComponent <HealthStation>().activeState&& !healthPickedUp)) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score //if (!healthPickedUp) //{ // healthPickedUp = true; // healthVialTimer = 1.5f; //} //if (healthVialTimer <= 0) //{ storedMedvial += Random.Range(other.GetComponent <HealthStation>().minMedvialOutput, other.GetComponent <HealthStation>().maxMedvialOutput); healthPickedUp = false; Debug.Log("Help"); if (storedMedvial > maxMedvial) { storedMedvial = maxMedvial; } //} //other.GetComponent<Animator>().SetTrigger("Play"); other.GetComponent <HealthStation>().activeState = false; //play animation of healthstation deactivating //healthVialTimer -= Time.deltaTime; } } #endregion #region Card & Panel if (other.tag == "Card" && Input.GetButtonDown("Interact")) { if (other.gameObject.GetComponent <KeyCard>().CurrentLevel == 6) { hasUniqueKey = true; } else { keyType = other.GetComponent <KeyCard>().CurrentLevel; //update the score hasKey = true; } //delete the card Destroy(other.gameObject); } if (other.tag == "CardPanel" && Input.GetButtonDown("Interact")) { //if the panel requires the master and the player has the master AND has not been activated if (other.GetComponent <CardPanel>().requiresMaster&& hasUniqueKey == true && !other.GetComponent <CardPanel>().xActivatedX) { other.GetComponent <CardPanel>().xActivatedX = true; } //if the player has the key, the panel has not been activated before AND does not need the master if (hasKey == true && !other.GetComponent <CardPanel>().xActivatedX && !other.GetComponent <CardPanel>().requiresMaster) { //play sound effect of door opening //destroy the door other.GetComponent <CardPanel>().xActivatedX = true; } //the "else" that goes after as it is denied if (!other.GetComponent <CardPanel>().xActivatedX) { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } #endregion #region DetPack w/ Interactables if (other.tag == "DetPack" && Input.GetButtonDown("Interact")) { if (storedDetPack >= maxDetPack) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score storedDetPack++; //delete the power cell Destroy(other.gameObject); } } //rad jammer gonna block yo screen unless you destroy it with a detpack if (other.gameObject.tag == "Jammer" && Input.GetButtonDown("Interact")) { //got more than 1 detpack, good, now make it go boom if (storedDetPack >= 1 && other.gameObject.GetComponent <Jammer>().isJamming) { other.gameObject.GetComponent <Jammer>().isJamming = false; storedDetPack--; } } if (other.tag == "WallDestroy" && Input.GetButtonDown("Interact")) { //got more than 1 detpack, good, now make it go boom if (storedDetPack >= 1 && !other.gameObject.GetComponent <WeakWallDestroy>().isGonnaBlow) { other.gameObject.GetComponent <WeakWallDestroy>().isGonnaBlow = true; storedDetPack--; } } #endregion #region Locker & Crate search if (other.gameObject.tag == "Locker" && Input.GetButtonDown("Interact")) { if (!other.gameObject.GetComponent <ObjectLooting>().searched) { if (other.gameObject.GetComponent <ObjectLooting>().healthUpgrade) //got more than 1 detpack, good, now make it go boom { if (maxHealth < highestHealth) { maxHealth += healthUpgradeIncrease; } } if (other.gameObject.GetComponent <ObjectLooting>().medvialUpgrade) { if (maxMedvial < highestMedvial) { maxMedvial += medvialUpgradeIncrease; } } if (other.gameObject.GetComponent <ObjectLooting>().powerCellUpgrade) { if (maxPowerCell < highestPowerCell) { maxPowerCell += powerCellUpgradeIncrease; } } if (other.gameObject.GetComponent <ObjectLooting>().detpackUpgrade) { if (maxDetPack < highestDetPack) { maxDetPack += detPackUpgradeIncrease; } } if (other.gameObject.GetComponent <ObjectLooting>().medvialPickUp) { if (storedMedvial < maxMedvial) { storedMedvial += Random.Range(other.gameObject.GetComponent <ObjectLooting>().minMedvials, other.gameObject.GetComponent <ObjectLooting>().maxMedvials); } } if (other.gameObject.GetComponent <ObjectLooting>().powerCellPickUp) { if (storedPowerCell < maxPowerCell) { storedPowerCell += Random.Range(other.gameObject.GetComponent <ObjectLooting>().minPowerCell, other.gameObject.GetComponent <ObjectLooting>().maxPowerCell); } } if (other.gameObject.GetComponent <ObjectLooting>().detpackPickUp) { if (storedDetPack < maxDetPack) { storedDetPack += Random.Range(other.gameObject.GetComponent <ObjectLooting>().minDetpack, other.gameObject.GetComponent <ObjectLooting>().maxDetpack); } } other.gameObject.GetComponent <ObjectLooting>().searched = true; } else { //play --NO SOUND-- } other.GetComponent <Animator>().SetTrigger("Play"); } #endregion #region SpinWheel if (other.tag == "SpinWheel" && Input.GetButton("Interact")) { chargingType = "SpinWheel"; spinWheelTimer += Time.deltaTime; if (spinWheelTimer >= spinWheel.interactTime) { spinWheel.wheelSpinComplete = true; wheelSpun = true; } if (wheelSpun) { spinWheelTimer = 0f; } } #endregion }
public static void LeftMouseUp(int x, int y) { if (Creation.CreatedElement != null) { return; //Don't select when the user is creating an object } if (draggingState == DraggingState.NONE) { if (rectangleSelecting) //Rectangle selection { selectionLineA.Visible = false; selectionLineB.Visible = false; selectionLineC.Visible = false; selectionLineD.Visible = false; int startX = Math.Min(mouseClickX, x); int startY = Math.Min(mouseClickY, y); int width = Math.Abs(mouseClickX - x); int height = Math.Abs(mouseClickY - y); List <ISelectable> objects = GetObjectsInRectangle(startX, startY, width, height); if (objects.Count > 0) { if (!ActionKey.IsDown(Action.SELECTION_ADD) && !ActionKey.IsDown(Action.SELECTION_REMOVE)) //Clear previous selection if the user does not want to add to selection { Selected.Clear(); } foreach (ISelectable obj in objects) { if (obj is IElement) { if (!ActionKey.IsDown(Action.SELECTION_REMOVE)) { if (!Selected.Contains(obj)) { Selected.Add((IElement)obj); } } else { if (Selected.Contains(obj)) { Selected.Remove((IElement)obj); } } } } } } else //Single selection { ISelectable objectAtMouse = GetObjectAtPixel(x, y); if (objectAtMouse != null) { if (objectAtMouse is IElement) { if (ActionKey.IsDown(Action.SELECTION_ADD)) { if (!Selected.Contains(objectAtMouse)) { Selected.Add((IElement)objectAtMouse); } else if (ActionKey.IsDown(Action.SELECTION_REMOVE)) { if (Selected.Contains((IElement)objectAtMouse)) { Selected.Remove((IElement)objectAtMouse); } } } else { TimeSpan timeSinceLastClick = DateTime.Now.Subtract(lastSingleSelectTime); if (timeSinceLastClick.Milliseconds > 200) { if (!ActionKey.IsDown(Action.SELECTION_REMOVE)) { Selected.Clear(); Selected.Add((IElement)objectAtMouse); } else if (Selected.Contains((IElement)objectAtMouse)) { Selected.Remove((IElement)objectAtMouse); } } else { if (Selected.Count == 1) { if (Selected[0] == objectAtMouse) { foreach (Drawable drawable in Drawable.Drawables) { if (!(drawable is IElement selectable)) { continue; } if (selectable.GetType() == Selected[0].GetType()) { if (selectable != Selected[0]) { if (!ActionKey.IsDown(Action.SELECTION_REMOVE)) { Selected.Add(selectable); } else if (Selected.Contains(selectable)) { Selected.Remove(selectable); } } } } } } } } lastSingleSelectTime = DateTime.Now; } } else if (!ActionKey.IsDown(Action.SELECTION_ADD) && !ActionKey.IsDown(Action.SELECTION_REMOVE)) { Selected.Clear(); } } rectangleSelecting = false; } else if (draggingState == DraggingState.MOVING_X || draggingState == DraggingState.MOVING_Y || draggingState == DraggingState.MOVING_Z) { new ActionMove(Selected.ToArray(), Vector3.Subtract(AveragePosition, positionAtStart)); Program.main.propertySelection.Refresh(); } else if (draggingState == DraggingState.ROTATING_X || draggingState == DraggingState.ROTATING_Y || draggingState == DraggingState.ROTATING_Z) { new ActionRotate(Selected.ToArray(), Vector3.Subtract(Selected[0].Rotation, rotationAtStart)); Program.main.propertySelection.Refresh(); } draggingState = DraggingState.NONE; gizmoLineX.Visible = false; gizmoLineY.Visible = false; gizmoLineZ.Visible = false; gizmoRotX.Rotation = Vector3.Zero; gizmoRotY.Rotation = Vector3.Zero; gizmoRotZ.Rotation = Vector3.Zero; clickingLeft = false; Renderer.InvalidateView(); Renderer.Invalidate(); }
public static void LeftMouseDown(int x, int y) { mouseClickX = x; mouseClickY = y; if (Creation.CreatedElement != null) { return; //Don't select when the user is creating an object } ISelectable objectAtMouse = GetObjectAtPixel(x, y); if (objectAtMouse == gizmoPosX) { gizmoLineX.Visible = true; gizmoLineX.Position = gizmoPosX.Position; draggingState = DraggingState.MOVING_X; positionAtStart = AveragePosition; } else if (objectAtMouse == gizmoPosY) { gizmoLineY.Visible = true; gizmoLineY.Position = gizmoPosY.Position; draggingState = DraggingState.MOVING_Y; positionAtStart = AveragePosition; } else if (objectAtMouse == gizmoPosZ) { gizmoLineZ.Visible = true; gizmoLineZ.Position = gizmoPosZ.Position; draggingState = DraggingState.MOVING_Z; positionAtStart = AveragePosition; } else if (objectAtMouse == gizmoRotX) { gizmoLineX.Visible = true; gizmoLineX.Position = gizmoRotX.Position; draggingState = DraggingState.ROTATING_X; rotationAtStart = Selected[0].Rotation; } else if (objectAtMouse == gizmoRotY) { gizmoLineY.Visible = true; gizmoLineY.Position = gizmoRotY.Position; draggingState = DraggingState.ROTATING_Y; rotationAtStart = Selected[0].Rotation; } else if (objectAtMouse == gizmoRotZ) { gizmoLineZ.Visible = true; gizmoLineZ.Position = gizmoRotZ.Position; draggingState = DraggingState.ROTATING_Z; rotationAtStart = Selected[0].Rotation; } else { clickingLeft = true; } }
internal DraggingEventArgs(PointerPoint point, DraggingState state, uint contactCount) { Pointer = point; DraggingState = state; ContactCount = contactCount; }
void Update() { // Ignore the collisions between the sword and the environment (mostly the enemy cause it would damage him) //Physics.IgnoreLayerCollision(0, 9, true); // Get the direction of input from the user Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (currentState == DraggingState.VERTICAL) { input.x = 0; } else if (currentState == DraggingState.HORIZONTAL) { input.y = 0; } // Normalize the input Vector2 inputDir = input.normalized; bool movementDisabled = false; // Debug addition to get around faster //bool running = Input.GetKey(KeyCode.LeftShift); // Set to walkSpeed in alpha test float targetSpeed = (/*(running) ? runSpeed : */ walkSpeed) * inputDir.magnitude; // Speed up the player overtime when they move currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, speedSmoothTime); if (inputDir != Vector2.zero) { /* ***THIS CODE LOCKS THE PLAYER ROTATION WHEN ATTACKING ANIMATION IS PLAYING*** * if (!(meleeSwipe.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1) && !meleeSwipe.IsInTransition(0)) * {*/ if (currentState == DraggingState.NONE) { // Set the target rotation to be equal to the direction that the player is facing float targetRotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg; // Change the rotation to the player to be equal to that direction with smoothing transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, turnSmoothTime); // Move the character relevant to the set current speed //transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World); if (!movementDisabled /* && !ifFallen*/) { controller.Move((transform.forward * currentSpeed) * Time.deltaTime); } } else { Vector3 dir = new Vector3(inputDir.x, 0, inputDir.y); if (!movementDisabled /* && !ifFallen*/) { controller.Move((dir * currentSpeed) * Time.deltaTime); } } //} } controller.Move(velocity * Time.deltaTime); // Add gravity to the player velocity += gravity * Time.deltaTime; // Subtract the velocity by the slowDownAmount to slow down the knockback velocity -= velocity * slowDownAmount; // If the velocity gets below a certain threshold, set it to zero if (velocity.magnitude < 0.35f) { velocity = Vector3.zero; } // Logic checks to make sure HealthBar array doesn't go out of bounds if (currentHealth > maxHealth) { currentHealth = maxHealth; } else if (currentHealth <= 0) { currentHealth = 0; } // 14 is the magic number so shut up if (maxHealth > 14) { maxHealth = 14; } // Only use the timer if the counter has been activated if (knockBackCounter > 0) { movementDisabled = true; knockBackCounter -= Time.deltaTime; } // Once the Counter reaches 0, removes the force applied to the enemy else if (knockBackCounter <= 0) { movementDisabled = false; } // If the player falls below a certain Y level, it will teleport to the AIFollower and take damage if (transform.position.y < -fallAmount) { Debug.Log("Player fallen off map"); TeleportToAI(); currentHealth -= 2; // Player takes damage upon falling into hole //playerFallen = false; } // Check if player took damage PlayerTookDamage(); // Check for animation plays PlayLightAnimation(); PlayHeavyAnimation(); if (currentHealth == 0 && DeathToMenu == true) { UnityEngine.SceneManagement.SceneManager.LoadScene(MainMenuName); //UnityEngine.SceneManagement.SceneManager.LoadScene("Main_Menu"); } //Box dragging if (Input.GetButtonUp("Interact")) { currentState = DraggingState.NONE; //Set velocity to zero //set box to null box = null; } if (Input.GetButtonDown("Medvial") && storedMedvial > 0 && currentHealth != maxHealth) { currentHealth++; storedMedvial--; } //Debug.DrawLine(transform.position + new Vector3(-0.5f, 5.0f, 0.0f), transform.position + new Vector3(0.5f, 5.0f, 0.0f), Color.red); healthVialTimer -= Time.deltaTime; }
//updated with on trigger stay void OnTriggerStay(Collider other) { // Block Dragging if (currentState == DraggingState.NONE) { if (other.name == "TopCollider" && Input.GetButton("Interact") || other.name == "BottomCollider" && Input.GetButton("Interact")) { box = other.transform.parent.gameObject; relativePosition = box.transform.position - transform.position; if (relativePosition.magnitude < 2.0f) { relativePosition.Normalize(); relativePosition *= 2.0f; } currentState = DraggingState.VERTICAL; } else if (other.name == "LeftCollider" && Input.GetButton("Interact") || other.name == "RightCollider" && Input.GetButton("Interact")) { box = other.transform.parent.gameObject; relativePosition = box.transform.position - transform.position; if (relativePosition.magnitude < 2.0f) { relativePosition.Normalize(); relativePosition *= 2.0f; } currentState = DraggingState.HORIZONTAL; } } //execution of enemy if (other.gameObject.tag == "Enemy") { bool enemyDeadCheck = other.gameObject.GetComponent <TrooperBehaviour>().xIsDownedX; if (other.gameObject.tag == "Enemy" && Input.GetButtonDown("Interact") && enemyDeadCheck == true) { other.gameObject.GetComponent <TrooperBehaviour>().xIsDeadX = true; } } // Powercell pickup if (other.gameObject.tag == "PowerCell" && Input.GetButtonDown("Interact")) { if (storedPowerCell >= maxPowerCell) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score storedPowerCell++; //delete the power cell Destroy(other.gameObject); } } // Door open -- this requires the panel object to have the tag 'Panel' if (other.gameObject.tag == "Panel" && Input.GetButtonDown("Interact")) { //if the player has 1 or more power cells and the panel has not been activated before if (storedPowerCell >= 1 && !other.gameObject.GetComponent <Panel>().xActivatedX) // panel activatd = false { //open the door storedPowerCell--; //play sound effect of door opening //destroy the door other.gameObject.GetComponent <Panel>().xActivatedX = true; } else { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } //health interact if (other.gameObject.tag == "Health" && Input.GetButtonDown("Interact")) { //if the player has less than max health if (currentHealth < maxHealth) { //sets up the amount to heal int healthGained = other.gameObject.GetComponent <HealthPickup>().healthRestoreAmount; //heal the player currentHealth = currentHealth + healthGained; //if player gains more than max health if (currentHealth > maxHealth) { //current health gets set to max health currentHealth = maxHealth; } //play sound effect of healing //destroy the door Destroy(other.gameObject); } else { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } if (other.gameObject.tag == "Card" && Input.GetButtonDown("Interact")) { if (other.gameObject.GetComponent <KeyCard>().CurrentLevel == 6) { hasUniqueKey = true; } else { keyType = other.gameObject.GetComponent <KeyCard>().CurrentLevel; //update the score hasKey = true; } //delete the card Destroy(other.gameObject); } if (other.gameObject.tag == "CardPanel" && Input.GetButtonDown("Interact")) { //if the panel requires the master and the player has the master AND has not been activated if (other.gameObject.GetComponent <CardPanel>().requiresMaster&& hasUniqueKey == true && !other.gameObject.GetComponent <CardPanel>().xActivatedX) { other.gameObject.GetComponent <CardPanel>().xActivatedX = true; } //if the player has the key, the panel has not been activated before AND does not need the master if (hasKey == true && !other.gameObject.GetComponent <CardPanel>().xActivatedX && !other.gameObject.GetComponent <CardPanel>().requiresMaster) { //play sound effect of door opening //destroy the door other.gameObject.GetComponent <CardPanel>().xActivatedX = true; } //the "else" that goes after as it is denied if (!other.gameObject.GetComponent <CardPanel>().xActivatedX) { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } // Detpack pickup if (other.gameObject.tag == "DetPack" && Input.GetButtonDown("Interact")) { if (storedDetPack >= maxDetPack) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score storedDetPack++; //delete the power cell Destroy(other.gameObject); } } // Health Station if (other.gameObject.tag == "HealthStation" && Input.GetButtonDown("Interact") || healthPickedUp) { if (storedMedvial >= maxMedvial || (!other.GetComponent <HealthStation>().activeState&& !healthPickedUp)) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score if (!healthPickedUp) { healthPickedUp = true; healthVialTimer = 1.5f; } if (healthVialTimer <= 0) { storedMedvial += Random.Range(other.GetComponent <HealthStation>().minMedvialOutput, other.GetComponent <HealthStation>().maxMedvialOutput); healthPickedUp = false; Debug.Log("Help"); if (storedMedvial > maxMedvial) { storedMedvial = maxMedvial; } } other.GetComponent <Animator>().SetTrigger("Activated"); other.GetComponent <HealthStation>().activeState = false; //play animation of healthstation deactivating } } //rad jammer gonna block yo screen unless you destroy it with a detpack if (other.gameObject.tag == "Jammer" && Input.GetButtonDown("Interact")) { //got more than 1 detpack, good, now make it go boom if (storedDetPack >= 1 && other.gameObject.GetComponent <Jammer>().isJamming) { other.gameObject.GetComponent <Jammer>().isJamming = false; storedDetPack--; } } if (other.gameObject.tag == "WallDestroy" && Input.GetButtonDown("Interact")) { //got more than 1 detpack, good, now make it go boom if (storedDetPack >= 1 && !other.gameObject.GetComponent <WeakWallDestroy>().isGonnaBlow) { other.gameObject.GetComponent <WeakWallDestroy>().isGonnaBlow = true; storedDetPack--; } } }
//updated with on trigger stay void OnTriggerStay(Collider other) { if (currentState == DraggingState.NONE) { if (other.name == "TopCollider" && Input.GetButton("Interact") || other.name == "BottomCollider" && Input.GetButton("Interact")) { box = other.transform.parent.gameObject; relativePosition = box.transform.position - transform.position; Debug.Log("booya"); if (relativePosition.magnitude < 2.0f) { relativePosition.Normalize(); relativePosition *= 2.0f; } currentState = DraggingState.VERTICAL; } else if (other.name == "LeftCollider" && Input.GetButton("Interact") || other.name == "RightCollider" && Input.GetButton("Interact")) { box = other.transform.parent.gameObject; relativePosition = box.transform.position - transform.position; Debug.Log("booya"); if (relativePosition.magnitude < 2.0f) { relativePosition.Normalize(); relativePosition *= 2.0f; } currentState = DraggingState.HORIZONTAL; } } //execution of enemy if (other.gameObject.tag == "Enemy") { bool enemyDeadCheck = collision.gameObject.GetComponent <TrooperBehaviour>().xIsDownedX; if (collision.gameObject.tag == "Enemy" && Input.GetKeyDown(KeyCode.E) && enemyDeadCheck == true) { other.gameObject.GetComponent <TrooperBehaviour>().xIsDeadX = true; } } // Powercell pickup if (collision.gameObject.tag == "PowerCell" && Input.GetKeyDown(KeyCode.E)) { if (storedPowerCell >= maxPowerCell) { //play sound of --NO--, DO NOT ADD to SCORE } else { //update the score storedPowerCell++; //delete the power cell Destroy(other.gameObject); } } // Door open -- this requires the panel object to have the tag 'Panel' if (collision.gameObject.tag == "Panel" && Input.GetKeyDown(KeyCode.E)) { //if the player has 1 or more power cells and the panel has not been activated before if (storedPowerCell >= 1 && !other.gameObject.GetComponent <Panel>().xActivatedX) // panel activatd = false { //open the door storedPowerCell--; //play sound effect of door opening //destroy the door other.gameObject.GetComponent <Panel>().xActivatedX = true; } else { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } //health interact if (collision.gameObject.tag == "Health" && Input.GetKeyDown(KeyCode.E)) { //if the player has less than max health if (currentHealth < maxHealth) { //sets up the amount to heal int healthGained = other.gameObject.GetComponent <HealthPickup>().healthRestoreAmount; //heal the player currentHealth = currentHealth + healthGained; //if player gains more than max health if (currentHealth > maxHealth) { //current health gets set to max health currentHealth = maxHealth; } //play sound effect of healing //destroy the door Destroy(other.gameObject); } else { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } if (collision.gameObject.tag == "Card" && Input.GetKeyDown(KeyCode.E)) { if (collision.gameObject.GetComponent <KeyCard>().CurrentLevel == 6) { hasUniqueKey = true; } else { keyType = collision.gameObject.GetComponent <KeyCard>().CurrentLevel; //update the score hasKey = true; } //delete the card Destroy(collision.gameObject); } if (collision.gameObject.tag == "CardPanel" && Input.GetKeyDown(KeyCode.E)) { //if the panel requires the master and the player has the master AND has not been activated if (collision.gameObject.GetComponent <CardPanel>().requiresMaster&& hasUniqueKey == true && !collision.gameObject.GetComponent <CardPanel>().xActivatedX) { collision.gameObject.GetComponent <CardPanel>().xActivatedX = true; } //if the player has the key, the panel has not been activated before AND does not need the master if (hasKey == true && !collision.gameObject.GetComponent <CardPanel>().xActivatedX && !collision.gameObject.GetComponent <CardPanel>().requiresMaster) { //play sound effect of door opening //destroy the door collision.gameObject.GetComponent <CardPanel>().xActivatedX = true; } //the "else" that goes after as it is denied if (!collision.gameObject.GetComponent <CardPanel>().xActivatedX) { //play sound effect of --NO--, DO NOT REMOVE FROM SCORE } } }
internal DraggingEventArgs(PointerPoint point, DraggingState state) { Pointer = point; DraggingState = state; }
// Update is called once per frame void Update() { print("hello where art though"); if (!beginClick) { print("going into the switch"); switch (state) { case DraggingState.DraggingValid: GetComponent <OutlineComponent>().setColor(Color.green); break; case DraggingState.DraggingInvalid: GetComponent <OutlineComponent>().setColor(Color.red); break; case DraggingState.DroppedInvalid: GetComponent <OutlineComponent>().setColor(Color.red); break; case DraggingState.DroppedValid: GetComponent <OutlineComponent>().setColor(Color.white); break; default: break; } } Store store = FindObjectOfType <Store>(); if (!completed) { if (costText == null) { print("adding a cost text!"); costText = GetComponentInChildren <TextDisplay>().Add(0); costText.text = "Cost: " + GetComponent <Item>().GetPrice(); } if (store.isPurchaseable(this.GetComponent <Item> ())) { if (fundsAlertText) { GetComponentInChildren <TextDisplay>().Remove(fundsAlertText); fundsAlertText = null; } if (state == DraggingState.DraggingValid) { costText.color = Color.green; } else { costText.color = Color.red; } } else { if (!fundsAlertText) { fundsAlertText = GetComponentInChildren <TextDisplay>().Add(1); fundsAlertText.text = "INSUFFICIENT FUNDS"; fundsAlertText.color = Color.red; } costText.color = Color.red; } } if (state == DraggingState.DraggingValid || state == DraggingState.DraggingInvalid) { if (Input.GetMouseButtonUp(0)) { DoneDragging(); } else { //GetComponentInChildren<Collider> ().enabled = false; //put placement code here //cast a ray to get where mouse is pointing in world Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100.0f, groundLayer)) { //now we'll look for objects within a radius, and find the closest object with CellScript CellScript closestCell = null; float closestDist = spawnDropRadius + 1.0f; Collider[] hitColliders = Physics.OverlapSphere(hit.point, spawnDropRadius); for (int i = 0; i < hitColliders.Length; i++) { CellScript foundCell = hitColliders [i].GetComponent <CellScript> (); if (foundCell != null) { float dist = (foundCell.transform.position - hit.point).magnitude; //foundCell.highlight (1.0f/dist); if (dist < closestDist) { closestCell = foundCell; closestDist = dist; } } } //if there was a closest one in radius, we set it as our spawnPoint if (closestCell) { if (closestCell != spawnPoint) { Store gameStore = FindObjectOfType <Store> (); gameStore.setSelectedItem(null); beginClick = false; spawnPoint = closestCell; spawnPoint.SetPreviewPosition(this.gameObject); } if (closestCell.IsOpen()) { state = DraggingState.DraggingValid; } else { state = DraggingState.DraggingInvalid; } } else { state = DraggingState.DraggingInvalid; } } } //enable collider is cool //GetComponentInChildren<Collider> ().enabled = true; //could do this on mouse exit, just means we'll only activate our GameObject when dragging //we'll disable the collider so that the OnMouseOver, etc. methods on the cells work properly through the object //would like to have some sort of ghosting effect in future, we'll put that in this method SetGhost(true); } }