Question by
kuba2109 · Mar 09 at 04:47 PM ·
gamelinerenderer
Line Renderer Problem
Hi, Im making a 2D platform Game and I need help. I have double jump and my line renderer shows were im jumping. But i need that if i jump twice the line renderer stops work so it shows the player that he cant jump and if i fall to the ground the line renderer will start working
Here s my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Player1 : MonoBehaviour
{
public float power;
public Rigidbody2D rb;
public Vector2 minPower;
public Vector2 maxPower;
public bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
private int ExtraJumps;
public int extraJumpValue;
TrajectoryLine tl;
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
void Start()
{
cam = Camera.main;
tl = GetComponent<TrajectoryLine>();
}
private void Update()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
if (isGrounded == true)
{
ExtraJumps = extraJumpValue;
}
if (Input.GetMouseButtonDown(0))
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
}
if (Input.GetMouseButton(0))
{
Vector3 currentPoint = cam.ScreenToWorldPoint(Input.mousePosition);
currentPoint.z = 15;
tl.RenderLine(startPoint, currentPoint);
}
if (Input.GetMouseButtonUp(0) && ExtraJumps > 0)
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
ExtraJumps--;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
tl.EndLine();
}
else if ((Input.GetMouseButtonUp(0) && ExtraJumps == 1 && isGrounded == false))
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
GetComponent<LineRenderer>().enabled = false;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
tl.EndLine();
}
}
}
and the Trajectory line script:
[RequireComponent(typeof(LineRenderer))] public class TrajectoryLine : MonoBehaviour { public LineRenderer lr;
private void Awake()
{
lr = GetComponent<LineRenderer>();
}
public void RenderLine(Vector3 startPoint, Vector3 endPoint)
{
lr.positionCount = 2;
Vector3[] points = new Vector3[2];
points[0] = startPoint;
points[1] = endPoint;
lr.SetPositions(points);
}
public void EndLine ()
{
lr.positionCount = 0;
}
} alt text
Comment
Your answer
Follow this Question
Related Questions
I need help with boss design. I am new to coding so any help would be nice. 0 Answers
Character moves without arrow keys 0 Answers
Broke Game -1 Answers
How to add "Press ESC to EXIT"? and exit the game? 1 Answer
Help for a Dash Script 1 Answer