void OnWizardCreate() { //spawn my plateform and change the transform GameObject myPlateform = new GameObject(); myPlateform.name = objectName; //myPlateform.transform.localRotation = Quaternion.EulerAngles(baseRotation); myPlateform.transform.position = basePosition; myPlateform.transform.localScale = size; if (GameObject.Find(parentObject)) { myPlateform.transform.parent = GameObject.Find(parentObject).transform; } //change the component to move the object BlockAlreadyMovingV2 plateformComponent = myPlateform.AddComponent <BlockAlreadyMovingV2> (); plateformComponent.direction = direction; plateformComponent.energie = energie; //add some more graphic myPlateform.AddComponent <MeshRenderer>().material = myMat; myPlateform.AddComponent <MeshFilter>().mesh = plateformeMesh; myPlateform.AddComponent <MeshCollider>().convex = true; }
void delock() { if (blockLock != null) { Gun_Unlock_Event.start(); StartCoroutine("turnRightUi"); blockLock = null; } }
void OnWizardOtherButton() //to update a target { if (Selection.activeTransform != null) { BlockAlreadyMovingV2 plateformComponent = Selection.activeTransform.GetComponent <BlockAlreadyMovingV2>(); if (plateformComponent != null) { } } }
void Update() { viseurObjects [0].fillAmount = viseurFill[0] + myEnergie / myEnergieMax * 4; viseurObjects [1].fillAmount = viseurFill [1] + myEnergie / myEnergieMax * 4 - 1; viseurObjects [2].fillAmount = viseurFill [2] + myEnergie / myEnergieMax * 4 - 2; viseurObjects [3].fillAmount = viseurFill [3] + myEnergie / myEnergieMax * 4 - 3; RaycastHit hita; if (Physics.SphereCast(transform.position, castSize, Camera.main.transform.TransformDirection(Vector3.forward), out hita, Mathf.Infinity, myMask) && hita.collider.GetComponent <BlockAlreadyMovingV2> () && lastPlateformSeen != hita.collider.gameObject && hita.collider.GetComponent <BlockAlreadyMovingV2> ().direction != new Vector3(0, 0, 0)) { if (lastParticuleDirection != null) { lastParticuleDirection.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleDirection, 6); } lastPlateformSeen = hita.collider.gameObject; lastParticuleDirection = Instantiate <GameObject>(ParticulesDirection); lastParticuleDirection.transform.position = lastPlateformSeen.transform.position; lastParticuleDirection.transform.LookAt(lastParticuleDirection.transform.position + hita.collider.GetComponent <BlockAlreadyMovingV2>().direction); lastParticuleDirection.transform.parent = lastPlateformSeen.transform; } else if (!Physics.SphereCast(transform.position, castSize, Camera.main.transform.TransformDirection(Vector3.forward), out hita, Mathf.Infinity, myMask)) { lastPlateformSeen = null; if (lastParticuleDirection != null) { lastParticuleDirection.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleDirection, 6); } } else { lastPlateformSeen = hita.collider.gameObject; } #region direction //donner une force float triger2 = Input.GetAxis("trigger2"); if ((triger2 > 0.2f || Input.GetMouseButtonDown(0)) && !stocked) { stocked = true; RaycastHit hit; if (Physics.Raycast(transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, myMask) && hit.collider.GetComponent <BlockAlreadyMovingV2>()) { BlockAlreadyMovingV2 myBlock = hit.collider.GetComponent <BlockAlreadyMovingV2>(); Gun_Don_Direction_Event.start(); myBlock.direction = Vector3.Normalize(new Vector3(myDirectionGo [1].transform.position.x - myDirectionGo [0].transform.position.x, myDirectionGo [1].transform.position.y - myDirectionGo [0].transform.position.y, myDirectionGo [1].transform.position.z - myDirectionGo [0].transform.position.z)); Debug.Log(lastParticuleDirection.name); lastParticuleDirection.transform.LookAt(lastParticuleDirection.transform.position + myBlock.direction); myBlock.ApplyTheVelocity(); } } else { stocked = false; } //inverse if (Input.GetKeyDown(KeyCode.Joystick1Button5) || Input.GetMouseButtonDown(1)) { RaycastHit hit; if (Physics.Raycast(transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, myMask) && hit.collider.GetComponent <BlockAlreadyMovingV2>()) { BlockAlreadyMovingV2 myBlock = hit.collider.GetComponent <BlockAlreadyMovingV2>(); Gun_Don_Direction_Event.start(); myBlock.direction = Vector3.Normalize(new Vector3(myDirectionGo [0].transform.position.x - myDirectionGo [1].transform.position.x, myDirectionGo [0].transform.position.y - myDirectionGo [1].transform.position.y, myDirectionGo [0].transform.position.z - myDirectionGo [1].transform.position.z)); lastParticuleDirection.transform.LookAt(lastParticuleDirection.transform.position + myBlock.direction); myBlock.ApplyTheVelocity(); } } #endregion #region Energise //take bool isTackingEnergie = false; if (Input.GetKey(KeyCode.Joystick1Button4) || Input.GetKey(KeyCode.A)) { RaycastHit energiseHit; if (Physics.SphereCast(transform.position, castSize, Camera.main.transform.TransformDirection(Vector3.forward), out energiseHit, Mathf.Infinity, myMask) && energiseHit.collider.GetComponent <BlockAlreadyMovingV2> ()) { BlockAlreadyMovingV2 myBlock = energiseHit.collider.GetComponent <BlockAlreadyMovingV2> (); if (myEnergie < myEnergieMax) { if (myBlock.energie > 0) { if (energiseTake && (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.A))) { float myAddedEnergie = myEnergieMax - myEnergie; if (myAddedEnergie <= myBlock.energie) { myEnergie += myAddedEnergie; myBlock.energie -= myAddedEnergie; } else { myEnergie += myBlock.energie; myBlock.energie = 0; } lastParticuleAspiration.GetComponent <ParticleSystem>().Emit((int)myEnergie / 3); lastParticuleAspiration.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleAspiration.gameObject, 2f); isTackingEnergie = false; } else { if (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.A) || lastPlateformSeen != energiseHit.collider.gameObject) { Gun_Absorbe_Energie_Event.start(); lastParticuleAspiration = Instantiate <GameObject>(ParticulesAspiration); lastParticuleAspiration.GetComponent <particleAttractorLinear>().target = this.transform; lastParticuleAspiration.transform.parent = energiseHit.collider.transform; lastParticuleAspiration.transform.position = energiseHit.collider.transform.position; Destroy(lastParticuleAspiration.gameObject, 8); energiseTake = true; energiseTakeTimer = 0.8f; } isTackingEnergie = true; myBlock.energie -= 3; myEnergie += 3; } if (myBlock.energie < 0f) { myBlock.energie = 0f; } myBlock.ApplyTheVelocity(); } } else { if (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.A)) { Gun_Min_Energie_Event.start(); } } myBlock.ApplyTheVelocity(); } else if (energiseHit.collider != null && energiseHit.transform.tag == "destructible") { if (myEnergie < myEnergieMax) { if (energiseHit.rigidbody.velocity.magnitude > 0) { if (energiseTake && (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.A))) { float myAddedEnergie = myEnergieMax - myEnergie; if (myAddedEnergie <= energiseHit.rigidbody.velocity.magnitude) { myEnergie += myAddedEnergie; energiseHit.rigidbody.velocity = new Vector3(0, 0, 0); } else { myEnergie += energiseHit.rigidbody.velocity.magnitude; Debug.Log(energiseHit.rigidbody.velocity.magnitude); energiseHit.rigidbody.velocity = new Vector3(0, 0, 0); } energiseHit.rigidbody.angularVelocity = new Vector3(0, 0, 0); lastParticuleAspiration.GetComponent <ParticleSystem>().Emit((int)myEnergie / 3); lastParticuleAspiration.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleAspiration.gameObject, 2f); isTackingEnergie = false; } else { if (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.A) || lastPlateformSeen != energiseHit.collider.gameObject) { Gun_Absorbe_Energie_Event.start(); lastParticuleAspiration = Instantiate <GameObject>(ParticulesAspiration); lastParticuleAspiration.GetComponent <particleAttractorLinear>().target = this.transform; lastParticuleAspiration.transform.parent = energiseHit.collider.transform; lastParticuleAspiration.transform.position = energiseHit.collider.transform.position; Destroy(lastParticuleAspiration.gameObject, 8); energiseTake = true; energiseTakeTimer = 0.8f; } isTackingEnergie = true; energiseHit.rigidbody.velocity -= new Vector3(1, 1, 1); energiseHit.rigidbody.angularVelocity -= new Vector3(1, 1, 1); if (energiseHit.rigidbody.velocity.x < 0) { energiseHit.rigidbody.velocity = new Vector3(0, energiseHit.rigidbody.velocity.y, energiseHit.rigidbody.velocity.z); } if (energiseHit.rigidbody.velocity.y < 0) { energiseHit.rigidbody.velocity = new Vector3(energiseHit.rigidbody.velocity.x, 0, energiseHit.rigidbody.velocity.z); } if (energiseHit.rigidbody.velocity.z < 0) { energiseHit.rigidbody.velocity = new Vector3(energiseHit.rigidbody.velocity.z, energiseHit.rigidbody.velocity.y, 0); } if (energiseHit.rigidbody.angularVelocity.x < 0) { energiseHit.rigidbody.angularVelocity = new Vector3(0, energiseHit.rigidbody.angularVelocity.y, energiseHit.rigidbody.angularVelocity.z); } if (energiseHit.rigidbody.angularVelocity.y < 0) { energiseHit.rigidbody.angularVelocity = new Vector3(energiseHit.rigidbody.angularVelocity.x, 0, energiseHit.rigidbody.angularVelocity.z); } if (energiseHit.rigidbody.angularVelocity.z < 0) { energiseHit.rigidbody.angularVelocity = new Vector3(energiseHit.rigidbody.angularVelocity.z, energiseHit.rigidbody.angularVelocity.y, 0); } myEnergie += 3; } } } else { if (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.A)) { Gun_Min_Energie_Event.start(); } } } } if (energiseTakeTimer > 0) { energiseTakeTimer -= Time.deltaTime; } else { energiseTake = false; } if (isTackingEnergie == false && lastParticuleAspiration != null) { lastParticuleAspiration.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleAspiration.gameObject, 10); } //give float triger1 = Input.GetAxis("trigger1"); bool isTackingEnergieGive = false; if (triger1 > 0.2f || Input.GetKey(KeyCode.E)) { RaycastHit hit; if (Physics.SphereCast(transform.position, castSize, Camera.main.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, myMask) && hit.collider.GetComponent <BlockAlreadyMovingV2> ()) { BlockAlreadyMovingV2 myBlock = hit.collider.GetComponent <BlockAlreadyMovingV2> (); if (myEnergie >= 3) { Debug.Log(triger1); Debug.Log(lastInputTrigger); if (energiseGift && (lastInputTrigger <= 0.09f || Input.GetKeyDown(KeyCode.E))) { lastParticuleAspirationGive.GetComponent <ParticleSystem>().Emit((int)myEnergie / 1); lastParticuleAspirationGive.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleAspirationGive.gameObject, 2.5f); isTackingEnergieGive = false; myBlock.energie += myEnergie; myEnergie = 0; } else { if (lastInputTrigger <= 0.09f || Input.GetKeyDown(KeyCode.E) || lastPlateformSeen != hit.collider.gameObject) { Gun_Don_Energie_Event.start(); lastParticuleAspirationGive = Instantiate <GameObject>(ParticulesAspiration); lastParticuleAspirationGive.GetComponent <particleAttractorLinear>().target = hit.collider.transform; lastParticuleAspirationGive.GetComponent <particleAttractorLinear>().speed = 5; lastParticuleAspirationGive.transform.parent = this.transform; lastParticuleAspirationGive.transform.position = new Vector3(this.transform.position.x, this.transform.position.y - 3f, this.transform.position.z); Destroy(lastParticuleAspirationGive.gameObject, 5); energiseGift = true; energiseGiftTimer = 0.8f; } myBlock.energie += 3; myEnergie -= 3; lastParticuleAspirationGive.GetComponent <ParticleSystem>().Emit((int)myEnergie / 3); } if (myBlock.energie < 0f) { myBlock.energie = 0f; } myBlock.ApplyTheVelocity(); } else { if (lastInputTrigger <= 0.09f || Input.GetKeyDown(KeyCode.E)) { Gun_Min_Energie_Event.start(); } } myBlock.ApplyTheVelocity(); } } if (energiseGiftTimer > 0) { energiseGiftTimer -= Time.deltaTime; } else { energiseGift = false; } if (isTackingEnergieGive == false && lastParticuleAspirationGive != null) { lastParticuleAspirationGive.GetComponent <ParticleSystem>().Stop(); Destroy(lastParticuleAspiration.gameObject, 10); } lastInputTrigger = triger1; #endregion #region Lock // Système de lock if (Input.GetMouseButtonDown(2) || Input.GetKeyDown(KeyCode.JoystickButton9)) { RaycastHit hit; if (Physics.SphereCast(transform.position, castSize, Camera.main.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, myMask) && hit.collider.GetComponent <BlockAlreadyMovingV2> ()) { Gun_Lock_Event.start(); //rb.useGravity = false; blockLock = hit.collider.GetComponent <BlockAlreadyMovingV2> (); blockLockDistanceBase = blockLock.transform.position - transform.position; if (blockLock == null) { StartCoroutine("turnLeftUi"); } } else if (blockLock != null) { Gun_Unlock_Event.start(); blockLock = null; StartCoroutine("turnRightUi"); // RaycastHit hit; // if (Physics.Raycast (transform.position, Camera.main.transform.TransformDirection (Vector3.forward), out hit, Mathf.Infinity, myMask) && hit.collider.GetComponent<BlockAlreadyMovingV2> ()) { // blockLock = hit.collider.GetComponent<BlockAlreadyMovingV2> (); // } } } #endregion }
void OnEnable() { myBlock = (BlockAlreadyMovingV2)target; }