- Home /
Question by
Mistrz_mobile · May 16 at 04:31 PM ·
collisionline drawing
How do I make a line collide with 3D objects?
I'm new to programing, and I'm trying to make a ink ball replica in 3D. I have a working bouncing ball, and a line draw script (Yes it's from a tutorial), but I tried a lot of methods and tutorials but the collision never works. Is there any way to make it collideable with 3D objects?
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class toutchdraw : MonoBehaviour
{
public LineRenderer line;
public GameObject Line;
Coroutine drawing;
private Vector3 startPos; // Start position of line
private Vector3 endPos; // End position of line
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartLine();
}
if (Input.GetMouseButtonUp(0))
{
FinishLine();
}
}
void StartLine()
{
if (drawing!=null)
{
StopCoroutine(drawing);
}
drawing = StartCoroutine(DrawLine());
}
void FinishLine()
{
StopCoroutine(drawing);
}
IEnumerator DrawLine()
{
GameObject newGameObject = Instantiate(Line as GameObject, new Vector3(0, 0, 0), Quaternion.identity);
LineRenderer line = newGameObject.GetComponent<LineRenderer>();
line.positionCount = 0;
while (true)
{
Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
position.y = 0;
line.positionCount++;
line.SetPosition(line.positionCount-1, position);
yield return null;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to know from which direction there is a collision with an object? in C# 1 Answer
Why does this script check for raycast collision? Is it necessary? 1 Answer
Jumping with raycasts causing issues? 2 Answers
why my object is sometimes going through walls ? 1 Answer
Avoid physics from collision 1 Answer