- Home /
Question by
slondono06 · Jan 26 at 01:24 PM ·
c#collisioncolliderlight
,How to add value to a Light range that is counting down.
I'm trying to get my code to increase the range of the Light when the player collides with an enemy. The lights range goes down over time but I cannot figure out how to get the range to go up by a value when en enemy is killed/collided with.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightFlicker : MonoBehaviour
{
public Light lightSource;
public float reduction;
public GameObject enemy;
public GameObject player;
public void Start()
{
lightSource.range = 65;
}
public void Update()
{
lightSource.range -= reduction * Time.deltaTime;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Enemy")
{
lightSource.range = lightSource.range + 5;
}
}
}
,I'm having trouble figuring out how to add 5 to the range when my player colliders with an enemy. I'm trying to make a game where the light from a generator expands when you kill an enemy. I'm able to get the light reducing in range to work but not the light getting bigger when a collision happens. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LightFlicker : MonoBehaviour
{
public Light lightSource;
public float reduction;
public GameObject enemy;
public GameObject player;
public void Start()
{
lightSource.range = 65;
}
public void Update()
{
lightSource.range -= reduction * Time.deltaTime;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Enemy")
{
lightSource.range = lightSource.range + 5;
}
}
}
Comment