Question by
bishwasbh · Nov 15, 2021 at 05:08 PM ·
animationerrorunity 2dtrailrenderer
Change trail rederer to it's default/original vaule.
How to set _trail
to its original value _defaultTrail
. I tried this (below) code, but unfortunately _defaultTrail
is also changing its value. Is _trail = _defaultTrail;
is a good way to do this? Is there any way you/I/we can do this?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCrossHair : MonoBehaviour
{
public Vector2 mouseCursorPosition;
private TrailRenderer _trail;
private TrailRenderer _defaultTrail;
private Animator _animator;
// Constants that may change later
private string IsShooting = "IsShooting";
void Awake()
{
_trail = GetComponent<TrailRenderer>();
_defaultTrail = GetComponent<TrailRenderer>();
_animator = GetComponent<Animator>();
}
void Update()
{
Cursor.visible = false;
mouseCursorPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = mouseCursorPosition;
if (Input.GetMouseButton(0))
{
_trail.startColor = Color.magenta;
_trail.endWidth = 1;
_trail.endColor = Color.green;
_animator.SetBool(IsShooting, true);
}
else
{
// HAVE A LOOK HERE
_trail = _defaultTrail;
print(_defaultTrail);
_animator.SetBool(IsShooting, false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Apk on android does not start. Reason: Animator | Не запускается Apk на андройд. Причина: Animator 0 Answers
CrossFade won't crossfade animation, it just jumps to it. 0 Answers
Unity Firebase Google SignIn Error Help 0 Answers
My animations started acting weirdly 0 Answers
How to fix "no overload for method get component takes 1 arguments" 1 Answer