Hi there friendly @Gotal.
Based on your code. Perhaps this helps? If it does, please accept my answer! :)
Otherwise, elaborate and I could try again.
using UnityEngine;
using System.Collections;
public class ObjectStopper : MonoBehaviour
{
public myObject targetObject; // not my real objects name
public float stopSpeed = 10f;
private bool isStopping;
void Update()
{
if ( isStopping )
{
// Mathf.Max => Prevents negative speed.
targetObject.speedObject = Mathf.Max(0f, targetObject.speedObject - stopSpeed * Time.deltaTime);
}
}
void OnTriggerEnter( Collider col )
{
if( col.tag == "frontOfObject" )
{
Debug.Log( "Stop me over time Senpai!" );
isStopping = true;
}
}
}
↧