I have some lava in my game. I want this lava to move when collided with. However I cannot add another collider onto my lava gameobject as I already have one so the player dies when the lava is collided with. So I need to get the code that makes the lava move from another script. is there a way to do this?
This is my script for the lava movement with “lavaMove()” being the method I would like to have activate when I collide with the other gameobject
using UnityEngine;
using System.Collections;
public class LavaMovement : MonoBehaviour
{
public Vector3 m_StartPosition;
public Vector3 m_EndPosition;
public float m_Speed = 1.0F;
public float m_Timer = 1.0F;
private float m_StartTime;
private float m_JourneyLength;
private float m_fracJourney;
void Start()
{
endPosition();
m_JourneyLength = Vector3.Distance(m_StartPosition, m_EndPosition);
}
void Update()
{
float distCovered = (Time.time - m_StartTime) * m_Speed;
m_fracJourney = distCovered / m_JourneyLength;
}
void OnTriggerEnter2D(Collider2D other)
{
Destroy(other.gameObject);
}
void endPosition()
{
Vector3 currentPosition = transform.position;
if (currentPosition == m_EndPosition)
{
Destroy(gameObject);
}
}
public void LavaMove()
{
transform.position = Vector3.Lerp(m_StartPosition, m_EndPosition, m_fracJourney); //Move Lava
}
}