Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by gianni123 · May 21, 2010 at 06:05 PM · triggercontrollerspline

how to start "spline controller" with trigger?

I set the script spline controllers "on a character" Player2, and everything works. but how to activate the script with a trigger

enum eOrientationMode { NODE = 0, TANGENT }

var SplineParent : GameObject; var Duration : float = 10.0; var OrientationMode : eOrientationMode = eOrientationMode.NODE; var WrapMode : eWrapMode = eWrapMode.ONCE; var AutoStart : boolean = true; var AutoClose : boolean = true; var HideOnExecute : boolean = true;

private var mSplineInterp : SplineInterpolator = null; private var mTransforms : Array = null;

@script AddComponentMenu("Splines/Spline Controller")

function OnDrawGizmos() { var trans : Array = GetTransforms();

if (trans.length < 2) return;

var interp = new SplineInterpolator(); SetupSplineInterpolator(interp, trans);

interp.StartInterpolation(null, false, WrapMode);

var prevPos : Vector3 = trans[0].position; for (c=1; c <= 100; c++) { var currTime:float = c Duration / 100.0; var currPos = interp.GetHermiteAtTime(currTime); var mag:float = (currPos-prevPos).magnitude 2.0; Gizmos.color = Color(mag, 0.0, 0.0, 1.0); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } }

function Start() { mSplineInterp = gameObject.AddComponent(SplineInterpolator);

mTransforms = GetTransforms();

if (HideOnExecute) DisableTransforms();

if (AutoStart) FollowSpline(); }

function SetupSplineInterpolator(interp:SplineInterpolator, trans:Array) : void { interp.Reset();

if (AutoClose) var step : float = Duration / trans.length; else step = Duration / (trans.length-1);

for (var c:int = 0; c < trans.length; c++) { if (OrientationMode == OrientationMode.NODE) { interp.AddPoint(trans[c].position, trans[c].rotation, step*c, Vector2(0.0, 1.0)); } else if (OrientationMode == OrientationMode.TANGENT) { if (c != trans.length-1) var rot : Quaternion = Quaternion.LookRotation(trans[c+1].position - trans[c].position, trans[c].up); else if (AutoClose) rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up); else rot = trans[c].rotation;

      interp.AddPoint(trans[c].position, rot, step*c, Vector2(0.0, 1.0));
   }

}

if (AutoClose) interp.SetAutoCloseMode(step*c); }

// We need this to sort GameObjects by name class NameComparer extends IComparer { function Compare(trA : Object, trB : Object) : int { return trA.gameObject.name.CompareTo(trB.gameObject.name); } }

// // Returns children transforms already sorted by name // function GetTransforms() : Array { var ret : Array = new Array();

if (SplineParent != null) { // We need to use an ArrayList because theres not Sort method in Array... var tempTransformsArray = new ArrayList();
var tempTransforms = SplineParent.GetComponentsInChildren(Transform);

   // We need to get rid of the parent, which is also returned by GetComponentsInChildren...
   for (var tr : Transform in tempTransforms)
   {
      if (tr != SplineParent.transform)
         tempTransformsArray.Add(tr);
   }

   tempTransformsArray.Sort(new NameComparer());
   ret = Array(tempTransformsArray);

}

return ret; }

// // Disables the spline objects, we generally don't need them because they are just auxiliary // function DisableTransforms() : void { if (SplineParent != null) { SplineParent.SetActiveRecursively(false); } }

// // Starts the interpolation // function FollowSpline() {
if (mTransforms.length > 0) { SetupSplineInterpolator(mSplineInterp, mTransforms); mSplineInterp.StartInterpolation(null, true, WrapMode); } }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by gianni123 · May 24, 2010 at 10:44 PM

SOLVED! i've disabled the "spline controller" and i've create another script attached at the trigger

Code:

function OnTriggerEnter (collision : Collider)
{
   if (collision.gameObject.tag == "Player")
   {
 GameObject.Find("objectwithsplinecontroller").GetComponent("SplineController").enabled=true;
}
}    

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image carolineRecord · Apr 03, 2015 at 01:55 AM 0
Share

When I attempted to set the enabled state in a helper function I got the error "set_enabled can only be called from the main thread." But it worked when I put it in the update function. (just incase this info is useful to others)

avatar image
0

Answer by Lucas Meijer 1 · May 22, 2010 at 10:14 PM

If this script does what you want it to do, but you want it to not work from the beginning, but later, you can add it to the gameobject trough script (initiated by a trigger) using AddComponent(name_of_your_script)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image carolineRecord · Apr 02, 2015 at 09:06 PM 0
Share

I've tried this solution and when I try to trigger the script not in the start funtion it says: "set_enabled can only be called from the main thread."

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Spline Controller documentation 0 Answers

How do I play trigger parameters properly in the animator controller / 1 Answer

Spline Controller (javascript) error 2 Answers

How to trigger a door with an object not first person controller 1 Answer

FPS Kit V2.0 & Uspeak 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges