private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player") && !Lifted) { LiftTarget = this; } }
// Use this for initialization void Start() { mNextShotTimeSeconds = Time.time + 5; // Wait 5 seconds before firing next shot // The droid will rise directly above its spawn location to a random height. Vector3 firstTargetLocation = new Vector3(transform.position.x, BASE_TARGET_LOCATION_HEIGHT + (Random.value * TARGET_LOCATION_HEIGHT_OFFSET), transform.position.z); SetTargetLocation(firstTargetLocation); mIsMovementActive = true; mPushable = GetComponent <Pushable>(); mPushable.Pushed += OnPushed; mLiftable = GetComponent <Liftable>(); mLiftable.Lifted += OnLifted; mLightningable = GetComponent <Lightningable>(); mLightningable.Lightninged += OnLightninged; mDestroyable = GetComponent <Destroyable>(); mDestroyable.Destroyed += Explode; mAudioSource = GetComponent <AudioSource>(); mAudioSource.clip = HoverLoopClip; mAudioSource.Play(); }
private void OnTriggerExit2D(Collider2D collision) { if (LiftTarget == this && collision.CompareTag("Player") && !Lifted) { LiftTarget = null; } }
public void PutDown() { if (carrying != null) { carrying.PutDown(); carrying = null; } }
void OnTriggerEnter(Collider pick) { Liftable liftable = pick.GetComponent <Liftable> (); if (liftable != null) { liftable.shadowZone(shadowPosition); } }
void OnTriggerExit(Collider pick) { Liftable liftable = pick.GetComponent <Liftable>(); if (liftable != null && colliding.Contains(liftable)) { colliding.Remove(liftable); } }
void OnTriggerEnter(Collider collider) { Liftable liftable = collider.GetComponent <Liftable>(); if (liftable != null && !liftable.IsAttached()) { liftable.Attach(guide); } }
void OnTriggerEnter(Collider pick) { Liftable liftable = pick.GetComponent <Liftable>(); if (liftable != null && !colliding.Contains(liftable)) { colliding.Add(liftable); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.E) && pickup.carrying != null) { Liftable liftable = pickup.carrying; pickup.PutDown(); Rigidbody rb = liftable.GetComponent <Rigidbody>(); rb.AddForce(transform.forward * thrust, ForceMode.Impulse); Debug.Log("throw"); } }
List <Liftable> colliding = new List <Liftable>(); // the list of things we're currently colliding with // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && colliding.Count > 0) { carrying = colliding[0]; carrying.Attach(guide); } else if (Input.GetMouseButtonUp(0) && carrying != null) { PutDown(); } }
void OnTriggerStay(Collider pick) { Liftable liftable = pick.GetComponent <Liftable> (); if (liftable != null) { liftable.enabled = true; if (Input.GetMouseButtonDown(0)) { liftable.PickingUp(guide); } if (Input.GetMouseButtonUp(0)) { liftable.PutDown(); } } }
//Build with Z void Build() { //If Z is pressed... if (Input.GetKey(KeyCode.Z)) { movelock = true; //Player can't move while building bool anyBuildable = false; //Prepare to search for buildable objects Liftable buildable = null; //Prepare a holder for the object we're building Collider2D[] circleHit = Physics2D.OverlapCircleAll(transform.position, GrabDistance); //Do a circle check, same as above foreach (Collider2D coll in circleHit) { if (coll.GetComponent <Liftable>()) { //Assign the thing we're going to build, then break so we only build one thing at a time. anyBuildable = true; buildable = coll.GetComponent <Liftable>(); break; } } //If we have something to build, build it. Refer to Liftable.cs for details if (anyBuildable) { movelock = false; buildable.Build(); } } //If Z is released prematurely, reset build progress if (Input.GetKeyUp(KeyCode.Z)) { //Check for things nearby Collider2D[] circleHit = Physics2D.OverlapCircleAll(transform.position, GrabDistance); foreach (Collider2D coll in circleHit) { if (coll.GetComponent <Liftable>()) { //If there's an aplicable object, reset its build progress coll.GetComponent <Liftable>().CancelBuild(); } } } }
protected override void Awake() { base.Awake(); //get components liftable = GetComponent <Liftable> (); //internal stuff behaviour = Behaviour.NORMAL; durability.maxHealthPoints = 3; durability.healthPoints = 3; durability.invincibleWindow = 0.5f; //set callbacks Durability.callback onDmg = durability.onDamaged; durability.onDamaged = (int diff) => { if (onDmg != null) { onDmg(diff); } FlashColor(1, 0, 0, 0.1f); }; Durability.callback onHld = durability.onHealed; durability.onHealed = (int diff) => { if (onHld != null) { onHld(diff); } FlashColor(0, 1, 0, 0.1f); }; Durability.callback onDstr = durability.onDestruction; durability.onDestruction = (int i) => { if (onDstr != null) { onDstr(i); } Instantiate(Resources.Load("Meat_Raw", typeof(GameObject)), transform.position, Quaternion.identity); }; }
//X to pickup object when nearby void Pickup() { if (Input.GetKeyDown(KeyCode.X)) { //Object that isnt carried, pick up first object on the stack if (carrying == null) { Collider2D[] circleHit = Physics2D.OverlapCircleAll(transform.position, GrabDistance); Liftable LiftableHit = null; //Find the first Liftable in the area and assign it foreach (Collider2D coll in circleHit) { if (coll.GetComponent <Liftable>() != null) { LiftableHit = coll.GetComponent <Liftable>(); } } //If something was found, Start carrying it, forcing it to follow the player's position if (LiftableHit != null) { if (LiftableHit.Carrier == null) { LiftableHit.Carrier = gameObject; carrying = LiftableHit; carrying.carried = true; } } } //Drop object when button is pressed but already holding something else { carrying.Carrier = null; //remove Carrier assignment carrying.carried = false; //Set caried false carrying.transform.position = TheGrid.NearestPointOnGrid(carrying.transform.position); //Snap the dropped bricks to the grid carrying = null; } } }
void OnCollisionEnter(Collision col) { if (State != BeeState.Shooting) { return; } m_Rigidbody.velocity = Vector3.zero; Liftable liftable = col.gameObject.GetComponent <Liftable>(); if (liftable != null) { m_Liftable = liftable; m_LocalTransform = liftable.transform.worldToLocalMatrix * transform.localToWorldMatrix; liftable.AddBee(); State = BeeState.StuckObject; sfxHitObject.Play(); } else { State = BeeState.StuckWall; sfxHitWall.Play(); } }
protected virtual void OnDrop(object sender, EventArgs e) { Liftable.Drop(_player.Physics); }
public void FixedUpdate() { if (LiftState == ForceLiftState.Selecting) { // If the Hair Trigger is activated, start drawing a selector if (ViveInput.GetPress(mHand, ControllerButton.HairTrigger)) { RaycastHit hit; // Raycast out from the hand position if (Physics.Raycast(transform.position, transform.forward, out hit)) { // Update the selector to be at the position of the collision if (mLiftSelector) { mLiftSelector.SetActive(true); mLiftSelector.transform.position = hit.point; } // Try to get a liftable from the collider. mCurrentLiftable = hit.collider.GetComponentInParent <Liftable>(); Renderer renderer = mLiftSelector.GetComponent <MeshRenderer>(); if (mCurrentLiftable) { renderer.material = PositiveLiftMaterial; } else { renderer.material = NegativeLiftMaterial; } } } else { mLiftSelector.SetActive(false); } if (ViveInput.GetPressDown(mHand, ControllerButton.FullTrigger) && mCurrentLiftable != null) { mLiftSelector.SetActive(false); LiftState = ForceLiftState.Lifting; mCurrentLiftable.Lifted(); } } else if (LiftState == ForceLiftState.Lifting) { if (ViveInput.GetPressDown(mHand, ControllerButton.Trigger)) { // Stop the object. Rigidbody liftableRigidbody = mCurrentLiftable.GetComponent <Rigidbody>(); liftableRigidbody.velocity = Vector3.zero; } if (ViveInput.GetPress(mHand, ControllerButton.Trigger)) { Rigidbody liftableRigidbody = mCurrentLiftable.GetComponent <Rigidbody>(); liftableRigidbody.AddForce(LiftForce * (transform.position - mPreviousPosition)); } else { mAudioSource.Stop(); } } mPreviousPosition = transform.position; }