Esempio n. 1
0
    void CastOutToTarget()
    {
        int        layer_mask = LayerMask.GetMask("Default");
        RaycastHit hit;

        Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * maxDistance.Value, Color.red);
        if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance.Value, layer_mask))
        {
            targetPosition = hit.point;
            //The object the projectile hit


            if (hit.collider.gameObject.tag == "GrapplePoint")
            {
                isBeingProjected    = true;
                currentGrapplePoint = hit.collider.gameObject.GetComponent <GrapplePointHitbox>();
                targetPosition      = currentGrapplePoint.EnableProjection();
                targetPoint.SetValid(true);
            }
            else
            {
                if (isBeingProjected)
                {
                    currentGrapplePoint.DisableProjection();
                    currentGrapplePoint = null;
                    isBeingProjected    = false;
                }
                targetPoint.SetValid(false);
            }
        }
        else
        {
            if (isBeingProjected)
            {
                currentGrapplePoint.DisableProjection();
                currentGrapplePoint = null;
                isBeingProjected    = false;
            }
            targetPosition = transform.position + transform.forward * maxDistance.Value;
            targetPoint.SetValid(false);
        }

        targetPoint.SetPosition(targetPosition);
    }