Question by 
               jm9calvelo · Nov 18, 2018 at 09:11 AM · 
                raycastunity 2dlinerenderer  
              
 
              Unity 2D: how to fire a renderline with raycast upward?
Please help! i'm quite new to unity so.... this is my code
for the gun script:
 public GameObject claw;
 public bool isShooting;
 public Animator playerheadAnimator;
 public claw clawScript;
 
 
 void Update () {
     if (Input.GetButtonDown("Fire1") && !isShooting)
     {
         LaunchClaw();
     }
 }
 void LaunchClaw ()
 {
      isShooting = true;
      playerheadAnimator.speed = 0;
      RaycastHit hit;
      Vector3 up = transform.TransformDirection(Vector3.up);
      
      if(Physics.Raycast(transform.position , up , out hit, 100))
      {
          claw.SetActive(true);
          clawScript.ClawTarget(hit.point);
      }
 }
 public void CollectedObject() {
     isShooting = false;
     playerheadAnimator.speed = 1;
 }
}
and for the claw script:
 public Transform origin;
 public float speed = 4f;
 public gun Gun;
 //add scoremanager variable
 
 private Vector3 target;
 private int appleValue = 100;
 private GameObject childObject;
 private LineRenderer lineRenderer;
 private bool hitApple;
 private bool retracting;
 
 
 void Awake ()
 {
     lineRenderer = GetComponent<LineRenderer>();
 }
 
 void Update () 
 {
     float step = speed * Time.deltaTime;
     transform.position = Vector3.MoveTowards (transform.position, target, step);
     lineRenderer.SetPosition(0, origin.position);
     lineRenderer.SetPosition(1, transform.position);
     if (transform.position == origin.position && retracting)
     {
         Gun.CollectedObject();
         if (hitApple)
         {
             //add points
             hitApple = false;
         }
         Destroy(childObject);
         gameObject.SetActive(false);
     }
 }
 
 public void ClawTarget (Vector3 pos)
 {
     target = pos;
 }
 
 void OnTriggerEnter (Collider other)
 {
     retracting = true;
     target = origin.position;
     
     if (other.gameObject.CompareTag("Apple"))
     {
         hitApple = true;
         childObject = other.gameObject;
         other.transform.SetParent(this.transform);
     }
     //else if (other.gameObject.CompareTag("wrong"))
     //
     //    hitwrong = false;
     //
     
 }
}
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                