Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411278 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 01:15:16 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Path System
Pages: [1]
Print
Author Topic: Path System  (Read 794 times)
elgauly
TIGBaby
*


View Profile
« on: March 18, 2017, 04:42:33 PM »

I'm creating a path system because the Unity engine doesn't provide any.

Let's say I have a script called CircularPath, this path is a circle shape path which has radius, center point and angle variables. The angle variable specifies where the object is on the circle circumference. Now, if I create the path object which holds the CircularPath script and I create a game object which I want it move in the path, I want the game object to be snapped to it's rightful position already in the editor mode and not only in play mode then how do I do it?

 

I tried using the attribute ExecuteInEditMode but it doesn't good for my need.

I hope someone can help me with that,

Thank you in advance.        
Logged
bateleur
Level 10
*****



View Profile
« Reply #1 on: March 23, 2017, 08:10:25 AM »

Assuming I understand your use of "already" here, I don't think you can do any better than ExecuteInEditMode combined with Application.isPlaying (maybe). In particular, there is no equivalent to Update() for editor mode in terms of a function that is called every frame even when nothing changes.

One thing you haven't specified, though, is how you associate an object with a path it is to follow. If I were coding this then the GameObject would have a path field specifying the path it is to follow. If that were the case you could do something like this:

Code:
using UnityEngine;

[ExecuteInEditMode]
public class MyComponent : MonoBehaviour {

 public CircularPath path;

 void Update() {
  if (Application.isPlaying) {
   // Do whatever we do when the game is running
   ...
  } else {
   if (path) {
    path.snapToPath(gameObject);
   }
  }
 }

}
Logged

oahda
Level 10
*****



View Profile
« Reply #2 on: March 24, 2017, 03:47:07 AM »

I'd leave out the Application.isPlaying unless that's really what you want, and instead conditionally compile stuff so that it only runs when working in Unity (whether the game is playing or not) but is completely discarded in the final build using #ifdef UNITY_EDITOR. Fairly sure ExecuteInEditMode should work just fine for what you're trying to do. Difficult to say where the problem is with the information provided.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic