void Start() { rb = GetComponent <Rigidbody>(); rope = GameManager.Rope; grappleTarget = GameObject.FindGameObjectWithTag("GrappleTarget").transform; player = GameManager.Player; }
public void InitRopePartDataOptions(RopeController ropeController, IRopePartDataOptions[] ropePartDatas) { for (int i = 0; i < ropePartDatas.Length; i++) { ropePartDatas[i].Init(ropeController); } }
public static void CreateNewRope(Vector3 localPosition, GameObject parent = null, uint segments = 5, float length = 5) { // Create the top level object (anchor-point) GameObject ropeEmpty = new GameObject("Rope"); if (parent) { ropeEmpty.transform.parent = parent.transform; ropeEmpty.transform.localPosition = localPosition; } else { ropeEmpty.transform.position = localPosition; } // Add a RopeController script RopeController ropeController = ropeEmpty.AddComponent <RopeController>(); ropeController._firstSegment = ropeEmpty; // Add a rigidbody ropeController._rigidbody = ropeEmpty.AddComponent <Rigidbody>(); ropeController._rigidbody.isKinematic = true; // Generate new segments ropeController.AddSegments(segments, length); // Load rope material ropeController._ropeMaterial = Resources.Load <Material>("Materials/RopeMaterial"); }
private void AttachToRopeNode(RopeNode ropeNode) { ropeController = ropeNode.RopeController; ropeController.AttachNinja(this); anchoredJoint2D.connectedBody = ropeNode.Rigidbody2D; anchoredJoint2D.enabled = true; currentRopeNode = ropeNode; }
private void Start() { rb = GetComponent <Rigidbody>(); rope = GetComponent <RopeController>(); cam = Camera.main.GetComponent <CameraController>(); pos = transform.position; activateMovement = true; }
private void OnTriggerEnter2D(Collider2D collision) { // if player hits the spike if (collision.tag == "Body") { GameObject bld = Instantiate(blood, collision.transform.position, Quaternion.identity); //Destroy(bld, 1.5f); GameObject RM = GameObject.Find("TrainingRestartManager"); if (RM != null) { //RM.GetComponent<TrainingRestart>().ReloadScene(); GameObject.Find("SceneFader").GetComponent <Animator>().SetTrigger("FadeOut"); GameObject.FindGameObjectWithTag("Player").transform.GetChild(6).GetComponent <RopeController>().ropeLock = true; } } // if snowball hits the spike if (collision.GetComponent <Snowball>() != null) { if (snowBallPop != null) { GameObject snowpop = Instantiate(snowBallPop, collision.transform.position, Quaternion.identity); //Destroy(snowpop, 1.5f); } GameObject player = GameObject.FindGameObjectWithTag("Player"); RopeController RC = player.transform.GetChild(6).GetComponent <RopeController>(); if (RC.rope != null) { if (RC.rope.connectedBody != null) { if (RC.rope.connectedBody == collision.GetComponent <Rigidbody2D>()) { RC.rope = null; Destroy(player.transform.GetChild(2).GetComponent <SpringJoint2D>()); } } } if (RC.ropeTwo != null) { if (RC.ropeTwo.connectedBody != null) { if (RC.ropeTwo.connectedBody == collision.GetComponent <Rigidbody2D>()) { RC.ropeTwo = null; Destroy(player.transform.GetChild(3).GetComponent <SpringJoint2D>()); } } } Destroy(collision.GetComponent <Rigidbody2D>()); Destroy(collision.gameObject); } }
void Start() { rb2d = GetComponent <Rigidbody2D>(); rb2d.velocity = Vector2.up * 5; //gives it upward force ropeController = gameObject.GetComponent <RopeController>(); animator = GetComponent <Animator>(); facingRight = true; syncPos = GetComponent <PlayerSyncSprite>(); maxRopeDistance = ropeController.maxRopeDistance; }
private void Detach() { if (ropeController != null) { lastRopeController = ropeController; ropeController.DetachRope(); ropeController = null; grabCooldown = -0.25f; } currentRopeNode = null; }
public static void CreateNewRopeMenuItem() { GameObject selected = Selection.activeGameObject; if (selected != null) { Debug.Log("Creating rope attached to : " + selected.name); } RopeController.CreateNewRope(Vector3.zero, selected); }
// Use this for initialization void Start() { grapplingHooks = new List<GraplingHook>(); thePlayer = GameObject.Find("Player"); playerClimbing = thePlayer.GetComponent<Climbing>(); playerRopeController = thePlayer.GetComponent<RopeController>(); Name = "GrapplingHook"; Image = Resources.Load<Sprite>("grapplinghook"); IsConsumable = true; Prefab = null; }
public RopeImagePart(RopeController ropeController, RopeImagePartDataOptions ropeImagePartData) { if (ropeController == null || ropeImagePartData.CarTransform == null || ropeImagePartData.CarImageTransform == null) { Debug.LogError("imagePart Initialize Failed"); return; } this.ropeImagePartData = ropeImagePartData; this.ropeController = ropeController; Debug.Log("imagePart Initialized"); }
public RopeVisualPart(RopeController ropeController, RopeVisualPartDataOptions ropeVisualPartData) { if (ropeController == null || ropeVisualPartData.LineRenderer == null) { Debug.LogError("visualPart Initialize Failed"); return; } this.ropeController = ropeController; this.ropeVisualPartData = ropeVisualPartData; Debug.Log("visualPart Initialized"); }
public RopePhysicsPart(RopeController ropeController, RopePhysicsPartDataOptions ropePhysicsPartData) { if (ropeController == null) { Debug.LogError("physicsPart Initialize Failed"); return; } this.ropeController = ropeController; this.ropePhysicsPartData = ropePhysicsPartData; Debug.Log("physicsPart Initialized"); }
public override void OnInspectorGUI() { serializedObject.Update(); DrawDefaultInspector(); RopeController instance = target as RopeController; if (GUILayout.Button(new GUIContent("Regenerate"))) { instance.RegenerateRope(); } serializedObject.ApplyModifiedProperties(); }
public void GameComplete() { if (MatchFinished != null) { MatchFinished(); } RopeController.DestroyAllRopes(); ninjaBodies = ninjaPicker.GetBodies(4); GameState = State.PlayerScreen; BloodParticle.DestroyAll(); currentLevel.gameObject.SetActive(false); participatingNinjas.Clear(); }
// Update is called once per frame void Update() { if (isLeftHandLeaking) { leakCounter += Time.deltaTime; Color oldColor = this.GetComponent <SpriteRenderer>().color; this.GetComponent <SpriteRenderer>().color = new Color(oldColor.r, oldColor.g, oldColor.b, (10 - leakCounter) / 10f); } if (isRightHandLeaking) { leakCounter += Time.deltaTime; Color oldColor = this.GetComponent <SpriteRenderer>().color; this.GetComponent <SpriteRenderer>().color = new Color(oldColor.r, oldColor.g, oldColor.b, (10 - leakCounter) / 10f); } if (hasShownPlayerLeak) { leakCounter += Time.deltaTime; Color oldColor = this.GetComponent <SpriteRenderer>().color; this.GetComponent <SpriteRenderer>().color = new Color(oldColor.r, oldColor.g, oldColor.b, (10 - leakCounter) / 10f); } if (leakCounter > breakAfterSeconds) { Instantiate(BreakEffect, transform.position, Quaternion.identity); GameObject player = GameObject.FindGameObjectWithTag("Player"); RopeController RC = player.transform.GetChild(6).GetComponent <RopeController>(); if (isLeftHandLeaking) { RC.rope = null; Destroy(player.transform.GetChild(2).GetComponent <SpringJoint2D>()); } if (isRightHandLeaking) { RC.ropeTwo = null; Destroy(player.transform.GetChild(3).GetComponent <SpringJoint2D>()); } Destroy(this.gameObject); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag != "Collectable") { if (collision.GetComponent <Stone>() != null) { if (collision.isTrigger == false) { collision.GetComponent <Stone>().Break(); } } GameObject player = GameObject.FindGameObjectWithTag("Player"); RopeController RC = player.transform.GetChild(6).GetComponent <RopeController>(); if (RC.rope != null) { if (RC.rope.connectedBody != null) { if (RC.rope.connectedBody == GetComponent <Rigidbody2D>()) { RC.rope = null; Destroy(player.transform.GetChild(2).GetComponent <SpringJoint2D>()); } } } if (RC.ropeTwo != null) { if (RC.ropeTwo.connectedBody != null) { if (RC.ropeTwo.connectedBody == GetComponent <Rigidbody2D>()) { RC.rope = null; Destroy(player.transform.GetChild(3).GetComponent <SpringJoint2D>()); } } } Instantiate(explosionAnim, transform.position, Quaternion.identity); Destroy(this.gameObject); } }
private void CheckNearestEvent() { float MaxDistance = 5.0f; if (rbNearestRope != null) { float dis = Vector2.Distance(rb.position, rbNearestRope.position); if (dis > MaxDistance) { NearestRope.Mode = RopeController.RopeMode.NotUsed; NearestRope = null; rbNearestRope = null; } else { MaxDistance = dis; } } if (GameController.DistanceToPoint != null) { foreach (GameController.DistanceToPointHandler element in GameController.DistanceToPoint.GetInvocationList()) { float dis = element.Invoke(rb.position, out Rigidbody2D Element, out RopeController rope); if (MaxDistance > dis) { if (NearestRope != null) { NearestRope.Mode = RopeController.RopeMode.NotUsed; } rbNearestRope = Element; NearestRope = rope; MaxDistance = dis; NearestRope.Mode = RopeController.RopeMode.Target; } } } CurrentPlayerPhase = TypePlayerPhase.ball; }
public void StartRound() { foreach (var level in levels) { level.gameObject.SetActive(false); } currentLevel.gameObject.SetActive(true); RopeController.DestroyAllRopes(); GameUiManager.Instance.HideAll(); currentScoresManager.Spawner = currentLevel.SpawnManager; if (RoundStart != null) { RoundStart(); } GameState = State.Playing; audioSource.PlayOneShot(start); }
public void Break() { if (currentBreakStage < 2) { currentBreakStage++; showNextBreakStage(currentBreakStage); } else { RopeController RC = GameObject.FindGameObjectWithTag("Player").transform.GetChild(6).GetComponent <RopeController>(); if (RC.rope != null) { if (RC.rope.connectedBody != null) { if (RC.rope.connectedBody == GetComponent <Rigidbody2D>()) { RC.rope = null; } } } if (RC.ropeTwo != null) { if (RC.ropeTwo.connectedBody != null) { if (RC.ropeTwo.connectedBody == GetComponent <Rigidbody2D>()) { RC.ropeTwo = null; } } } Instantiate(BreakEffect, transform.position, Quaternion.identity); Destroy(this.gameObject); } }
public void Init(RopeController ropeController) { ropePart = new RopeVisualPart(ropeController, this); }
float Distance(Vector2 vector, out Rigidbody2D data, out RopeController rope) { data = rb; rope = this; return(Vector2.Distance(rb.position, vector)); }
public void Init(RopeController ropeController) { ropePart = new RopeImagePart(ropeController, this); }
private void Start() { rope = GameManager.Rope; player = GameManager.Player; weapon = GameManager.CurrentWeapon; }
private void Roping() { if (input.Roped && input.RightStick.magnitude > 0.2f) { var direction = input.RightStick; var rayHits = Physics2D.Raycast(transform.position, direction, 10.0f, 1 << LayerMask.NameToLayer("Ropables")); Detach(); ropeController = Instantiate(ropeControllerPrefab, transform.position, Quaternion.identity); audioSource.PlayOneShot(rope); if (rayHits.transform != null) { var targetRigidbody = rayHits.transform.GetComponent <Rigidbody2D>(); ropeController.AttachRope(rayHits.point, this, targetRigidbody); anchoredJoint2D.enabled = true; rigidbody.AddForce(direction.normalized); } else { var point = (Vector2)transform.position + (direction.normalized * 10); ropeController.AttachRope(point, this); Destroy(ropeController.LastRopeNode.GetComponent <RopeNode>().gameObject); ropeController = null; AnchoredJoint2D.enabled = false; } } else if (input.RopeUp) { Detach(); } if (ropeController != null && ropeController.LastRopeNode != null) { float horizontal = input.LeftStick.x; if (horizontal != 0) { Vector2 ropeDirection = (transform.position - ropeController.LastRopeNode.position).normalized, swingDirection = Quaternion.Euler(0, 0, 90 * Mathf.Sign(horizontal)) * ropeDirection; Vector2 force = (ropeDirection + swingDirection) * ropeSwaySpeed; rigidbody.AddForceAtPosition(force, transform.position + new Vector3(0, -1)); } } else { grabCooldown += Time.deltaTime; } if (currentRopeNode != null || (ropeController != null && ropeController.IsAttached)) { float vertical = input.LeftStick.y; if (vertical != 0 && Mathf.Abs(vertical) > 0.75f) { float check, timeCheck = currentRopeNode != null ? verticalTime : verticalRopeLengthTime; if (vertical < 0) { check = verticalDown += Time.deltaTime; verticalUp = 0.0f; } else { check = verticalUp += Time.deltaTime; verticalDown = 0.0f; } if (check >= timeCheck) { VerticalInput(vertical); verticalUp = 0.0f; verticalDown = 0.0f; } } } }
public void Init(RopeController ropeController) { ropePart = new RopePhysicsPart(ropeController, this); }
public void RemoveRopeController() { ropeController = null; }