"Komatsu teaches you to swim and develop" unity practical skills draw a line before Gameobject

Source: Internet
Author: User

Tag: no 51cto

Sometimes you need to check the scene in the project.

There are two points in this, and the calculation of the dash and front of the character

Dash with Lineranderer

The character is right in front of

Go.transform.forward + go.transform.position

The coordinates of the characters plus the forward direction of the characters.

(When I first hardheaded thinking of the front of the Go.transform.forward is not the front of the character, but if not add their own coordinates, it is only a direction, that is, this coordinate is only relative to the origin of the direction, plus coordinates is the point you want)

using System.Collections;  using System.Collections.Generic;  using UnityEngine;  public class DrawLine : MonoBehaviour {      public LineRenderer line;      public GameObject go;      // Use this for initialization      void Start () {     }      void Update()      {          Vector3 targetPos = go.transform.forward + go.transform.position;          line.SetPosition(0, go.transform.position);          line.SetPosition(1, targetPos);      }  }  

If it's just debug, there's an easier way.

Debug.DrawRay()Debug.DrawLine()

"Komatsu teaches you to swim and develop" unity practical skills draw a line before Gameobject

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.