• 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
Question by HolBol · Jul 11, 2010 at 02:01 PM · javascripttrailbce0020slip

enabling trail renderer

I am putting skidmarks in my game with a trail renderer that activates when the tire slips. I have this so far:

// Define the variables used in the script, the Corresponding collider is the wheel collider at the position of // the visible wheel, the slip prefab is the prefab instantiated when the wheels slide, the rotation value is the // value used to rotate the wheel around it's axel. var CorrespondingCollider : WheelCollider; var SlipPrefab : GameObject; private var RotationValue : float = 0.0;

function Update () {

 // define a hit point for the raycast collision
 var hit : RaycastHit;
 // Find the collider's center point, you need to do this because the center of the collider might not actually be
 // the real position if the transform's off.
 var ColliderCenterPoint : Vector3 = CorrespondingCollider.transform.TransformPoint( CorrespondingCollider.center );

 // now cast a ray out from the wheel collider's center the distance of the suspension, if it hit something, then use the "hit"
 // variable's data to find where the wheel hit, if it didn't, then se tthe wheel to be fully extended along the suspension.
 if ( Physics.Raycast( ColliderCenterPoint, -CorrespondingCollider.transform.up, hit, CorrespondingCollider.suspensionDistance + CorrespondingCollider.radius ) ) {
     transform.position = hit.point + (CorrespondingCollider.transform.up * CorrespondingCollider.radius);
 }else{
     transform.position = ColliderCenterPoint - (CorrespondingCollider.transform.up * CorrespondingCollider.suspensionDistance);
 }

 // now set the wheel rotation to the rotation of the collider combined with a new rotation value. This new value
 // is the rotation around the axle, and the rotation from steering input.
 transform.rotation = CorrespondingCollider.transform.rotation * Quaternion.Euler( RotationValue, CorrespondingCollider.steerAngle, 0 );
 // increase the rotation value by the rotation speed (in degrees per second)
 RotationValue += CorrespondingCollider.rpm * ( 360/60 ) * Time.deltaTime;

 // define a wheelhit object, this stores all of the data from the wheel collider and will allow us to determine
 // the slip of the tire.
 var CorrespondingGroundHit : WheelHit;
 CorrespondingCollider.GetGroundHit( CorrespondingGroundHit );

 // if the slip of the tire is greater than 2.0, and the slip prefab exists, create an instance of it on the ground at
 // a zero rotation.
 if ( Mathf.Abs( CorrespondingGroundHit.sidewaysSlip ) > 2.0 ) {
     if ( SlipPrefab ) {
         Instantiate( SlipPrefab, CorrespondingGroundHit.point, Quaternion.identity );
     }
 }
 if ( Mathf.Abs( CorrespondingGroundHit.sidewaysSlip ) > 2.0 ) {
         TrailRenderer.enabled = true; //THIS IS THE PROBLEM
     }
 }

}

What i have here is working, apart from the last section with TrailRenderer. I get an error of

BCE0020: An instance type of 'UnityEngine.Renderer' is required to access non static member 'enabled'.

how do i fix this?

Comment
SepM

People who like this

1 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by fherbst · Jul 11, 2010 at 02:11 PM

Use GetComponent(TrailRenderer).enabled = true instead.

TrailRenderer (uppercase) is the class name, but you want the particular instance on your gameObject. Many classes (like Rigidbody) have direct access names (GameObject.rigidbody), but TrailRenderer hasn't, so you have to use GetComponent to access it.

Comment
Tetrad
Persona
Qwerty
BiG
SepM

People who like this

5 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 HolBol · Jul 11, 2010 at 02:18 PM 0
Share

Thanks that works, but how would i get it so the trails stay there even when it's not active, or is that not possible?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

what's wrong with this?? 2 Answers

Setting Scroll View Width GUILayout 1 Answer

An instance of type X is required to access non static member Y [javascript] 4 Answers

An instance of type 'TurretControl' is required to access non static member 'Shoot'. 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