Get the Transform from Gameobjects in arrays to make a Line by Clicking the Mouse.
hei guys, im new to Coding in Unity and i want to make an game where you have 8 clicks, when you click on the Screen a path from the start location to the Click location apears and when you click another time a line apears from the last click location to the new one .... and so on. i have made a Scirpt by using the Line Renderer, and i made the script for spawning the "Waypoint" prefabs on the Mouse Position and renaming in by +1 . But how do i apply the Transform from the Prefabs to the Trnasform Array in the Line Renderer Script ??. This is an Video how it looks like when i spawn the Prefabs: https://www.youtube.com/watch?v=HLq9MoUcO3I&feature=youtu.be
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lr_Testing : MonoBehaviour
{
[SerializeField] public Transform[] points;
[SerializeField] private lr_LineController line;
public GameObject Waypoint;
private int anzahl = 0;
public int NumbersofPoints = 1;
void Start()
{
line.SetUpLine(points);
Waypoint.name = "Waypoint";
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Vector2 mousePos = Input.mousePosition;
Vector2 objectPos = mousePos;
Instantiate(Waypoint, objectPos, Quaternion.identity);
anzahl += 1;
Waypoint.name = "Waypoint" + anzahl;
NumbersofPoints += 1;
points = new Transform[NumbersofPoints];
}
}
}
Your answer
Follow this Question
Related Questions
Can someone tell me how to restart the scene if my player hits two objects 2 Answers
destructible tilemap, destroying tiles through overlapcircle 1 Answer
Question about tiles 1 Answer
How can i stop my shooting animation after playing? 0 Answers
How to render text on top of the objects that are generated on the map using a script? 1 Answer