init
This commit is contained in:
commit
bd5b1556ff
269 changed files with 6249829 additions and 0 deletions
69
Assets/Scripts/Grapple.cs
Normal file
69
Assets/Scripts/Grapple.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Grapple : MonoBehaviour{
|
||||
|
||||
public GameObject selector;
|
||||
public float rotationSpeed;
|
||||
|
||||
Rigidbody2D rb2d;
|
||||
GameObject player;
|
||||
|
||||
void Start(){
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
player = GameObject.FindGameObjectWithTag("Player");
|
||||
selector.SetActive(false);
|
||||
}
|
||||
|
||||
void Update(){
|
||||
selector.transform.Rotate(0, 0, rotationSpeed);
|
||||
}
|
||||
|
||||
void OnMouseOver(){
|
||||
if (Vector2.Distance(player.transform.position, transform.position) <= 10){
|
||||
selector.SetActive(true);
|
||||
player.GetComponent<PlayerController>().ableToGrapple = true;
|
||||
}else{
|
||||
selector.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool grappled;
|
||||
|
||||
void OnMouseExit(){
|
||||
if (!grappled){
|
||||
selector.SetActive(false);
|
||||
if (!player.GetComponent<PlayerController>().grappled){
|
||||
player.GetComponent<PlayerController>().ableToGrapple = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseDown(){
|
||||
if(Vector2.Distance(player.transform.position, transform.position) <= 10){
|
||||
grappled = true;
|
||||
SpringJoint2D grapple = player.GetComponent<SpringJoint2D>();
|
||||
player.GetComponent<PlayerController>().grappled = true;
|
||||
player.GetComponent<CapsuleCollider2D>().isTrigger = true;
|
||||
LineRenderer line = player.GetComponent<LineRenderer>();
|
||||
line.SetPosition(1, transform.position);
|
||||
line.enabled = true;
|
||||
grapple.connectedBody = rb2d;
|
||||
grapple.distance = Vector2.Distance(player.transform.position, transform.position) - 1f;
|
||||
grapple.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseUp(){
|
||||
grappled = false;
|
||||
SpringJoint2D grapple = player.GetComponent<SpringJoint2D>();
|
||||
LineRenderer line = player.GetComponent<LineRenderer>();
|
||||
player.GetComponent<PlayerController>().grappled = false;
|
||||
player.GetComponent<CapsuleCollider2D>().isTrigger = false;
|
||||
line.enabled = false;
|
||||
grapple.enabled = false;
|
||||
selector.SetActive(false);
|
||||
player.GetComponent<PlayerController>().ableToGrapple = false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue