i wanna u modifyy that scriptt i wanna bool namedd isOwnLocalModify its its true then i…
- User
i wanna u modifyy that scriptt
i wanna bool namedd isOwnLocalModify
its its true then i wanna its using local position of object
its must onenable get current position and starts moving like vector3 varialbes in local way i mean if vector3 secondPosition is 0,3,0 and is initial position is 0, -1, 0
then i wanna object transform oneanble moves current position -1 on y thats move from position to obejct transform oneanble position + y 3 from secondPosition
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; public class RaiseMobEffect : MonoBehaviour { public Transform PowerElectricity;
[Header("Event")] public UnityEvent onSpawnEvent; public UnityEvent onReachDestinationEvent; [Header("Raise")] public Vector2 invokeRange = new Vector2(1f, 3f); // Range for invoking events [Header("Point")] public Vector3 initialPosition = new Vector3(0, -3, 0); // Initial position of the mob public bool enableAutoSecond = true; // Initial position of the mob public Vector3 secondPosition = new Vector3(0, 5, 0); // Second position to move the mob public Transform mobTransform; // Reference to the mob’s transform public float raycastLength = 10f; // Length for the raycast private void OnDrawGizmos() { // Draw a box at the initial position Gizmos.color = Color.red; Gizmos.DrawWireCube(initialPosition, Vector3.one); // Draw a small box at the second position Gizmos.color = Color.green; Gizmos.DrawWireCube(secondPosition, Vector3.one * 0.5f); // Draw a line from the initial position downwards for raycasting visualization Gizmos.color = Color.blue; Gizmos.DrawLine(initialPosition, initialPosition + Vector3.down * raycastLength); } private void OnEnable() {if (mobTransform ==null) mobTransform=this.transform; if (enableAutoSecond) secondPosition = this.mobTransform.position; // Invoke the first event onSpawnEvent?.Invoke(); // Perform a raycast if (Physics.Raycast(initialPosition, Vector3.down, raycastLength)) { // If raycast hits, start coroutine to move the mob StartCoroutine(MoveMobToPosition(secondPosition, Random.Range(invokeRange.x, invokeRange.y))); } } private IEnumerator MoveMobToPosition(Vector3 targetPosition, float duration) { float elapsedTime = 0f; Vector3 startingPosition = mobTransform.position; while (elapsedTime < duration) { mobTransform.position = Vector3.Lerp(startingPosition, targetPosition, elapsedTime / duration); elapsedTime += Time.deltaTime; yield return null; } mobTransform.position = targetPosition; // Invoke the second event after reaching the destination onReachDestinationEvent?.Invoke(); }}
- Assistant
- User
i have that scriptt
its works in world space there 2 Vector3 variables targetPosition is bad cause its world like
vector3 its world position like i wanna its be works here like offset
write here necceasaryy voidss to make it works not like world vector3
only write lines that i need replace in answe
- Assistant
- User
- Assistant