Professional Documents
Culture Documents
Testfile
Testfile
using System.Collections;
/*IMPORTANT NOTE WHEN USING GRAPPLING HOOK: Grappling Hook does not require you to touch the
grapple point, just that you touch in the direction of the point*/
public class gHookS : touchInfoS {
GameObject vine;
//Vector2 dirVect;
public Vector2 vineEnd;
//rate which you climb the vine
public float pullRate=12f;
//length of hook
public int vineMax=10;
LayerMask collisionMask;
public Vector2 pullVector;
int testnum=0;
/*This block of code is only executed if the vine hits a surface within range and the mouseClick/touch
position is above the player height
*/
if (dirVect.y >= 0 && (vHit == true && vHit.collider.name.Contains("GrapplePoint")==true))
{
float angle = (180 * Mathf.Acos(dirVect.x)) / Mathf.PI;
/*This code creates the vine and transforms it accordingly*/
if (vine == null)
{
vine = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
vine.name = "Vine";
vine.transform.position = new Vector3(0, 0, 0);
}
Vector3 vScale = vine.transform.localScale;
vScale.y = vHit.distance / 2;
vScale.x = vScale.z = 0.2f;
vine.transform.localScale = vScale;
Vector2 vPos;
vPos = (float)(vine.transform.localScale.y) * dirVect +
(Vector2)this.gameObject.GetComponent<Collider2D>().bounds.center;
vine.transform.position = vPos;
vine.transform.rotation = Quaternion.Euler(0, 0, angle - 90);
vineEnd = vine.transform.localScale.y * dirVect + (Vector2)vine.transform.position;
//Debug.Log(tempCos);
return true;
}
else
{
destroyVine();
return false;
}
}
//If the vine is summoned by an enemy
else
{
dirVect = Vector2.up;
vHit = Physics2D.Raycast(this.gameObject.GetComponent<Collider2D>().bounds.center,
Vector2.up, 100, collisionMask);
vineMax = 100;
//Debug.Log(vHit.collider.name+" "+vHit.distance);
vine = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
vine.name = "Web";
vine.transform.position = new Vector3(0, 0, 0);
Vector3 vScale = vine.transform.localScale;
vScale.y = vHit.distance / 2;
vScale.x = vScale.z = 0.2f;
vine.transform.localScale = vScale;
Vector2 vPos;
vPos = (float)(vine.transform.localScale.y) * dirVect +
(Vector2)this.gameObject.GetComponent<Collider2D>().bounds.center;
vine.transform.position = vPos;
vineEnd = vine.transform.localScale.y * dirVect + (Vector2)vine.transform.position;
return true;
}
}