Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jan 23, 2017 at 03:45 PM by RonanSmithDev for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by RonanSmithDev · Jan 18, 2017 at 09:25 PM · c#errorprogrammingcompile-errorparsing error

Coding Errors

I have been trying to use this code from another question on Unity community to make my charector controller stick to platforms. I am getting compile errors so cant use it, I would ask on the actual question but it is from 2009 so not sure if users are still active.

Original question: http://answers.unity3d.com/questions/8207/charactercontroller-falls-through-or-slips-off-mov.html

My Errors: Assets/JKeepCharOnPlatform.cs(79,36): error CS1026: Unexpected symbol ;', expecting )' Assets/JKeepCharOnPlatform.cs(79,37): error CS1026: Unexpected symbol =', expecting )' Assets/JKeepCharOnPlatform.cs(79,66): error CS1026: Unexpected symbol =', expecting )' Assets/JKeepCharOnPlatform.cs(89,1): error CS8025: Parsing error

I am new to coding and have no idea how to fix, Here is my code:

 using UnityEngine;
 using System.Collections;
 
 
 /** 
   Helps keeping charactercontroller entities nicely on the platform
   Needs a Collider set as trigger in the gameobject this script is added to
   works best if collider is bit smaller as platform but extends quite a lot
   (say .5m or so) above the platform, As the platform possibly already has
   a normal collider the easiest way is to add a GameObject to the platform,
   give it a trigger collider and add this script. The yOffset is the vertical 
   offset the character should have above the platform (a good value to start
   with is half the y value of the Collider size).
  */
 public class JKeepCharOnPlatform : MonoBehaviour
 {
 
 
     // helper struct to contain the transform of the player and the
     // vertical offset of the player (how high the center of the
     // charcontroller must be above the center of the platform)
     public struct Data
     {
         public Data(CharacterController ctrl, Transform t, float yOffset)
         {
             this.ctrl = ctrl;
             this.t = t;
             this.yOffset = yOffset;
         }
         public CharacterController ctrl; // the char controller
         public Transform t; // transform of char
         public float yOffset; // y offset of char above platform center
     };
     public float verticalOffset = 0.25f; // height above the center of object the char must be kept
                                          // store all playercontrollers currently on platform
     private Hashtable onPlatform = new Hashtable();
     // used to calculate horizontal movement
     private Vector3 lastPos;
     void OnTriggerEnter(Collider other)
     {
         CharacterController ctrl = other.GetComponent(typeof(CharacterController)) as CharacterController;
         // make sure we only move objects that are rigidbodies or charactercontrollers.
         // this to prevent we move elements of the level itself
         if (ctrl == null) return;
         Transform t = other.transform; // transform of character
                                        // we calculate the yOffset from the character height and center
         float yOffset = ctrl.height / 2f - ctrl.center.y + verticalOffset;
         Data data = new Data(ctrl, t, yOffset);
         // add it to table of characters on this platform
         // we use the transform as key
         onPlatform.Add(other.transform, data);
     }
     void OnTriggerExit(Collider other)
     {
         // remove (if in table) the uncollided transform
         onPlatform.Remove(other.transform);
     }
     void Start()
     {
         lastPos = transform.position;
     }
     void Update()
     {
         Vector3 curPos = transform.position;
         float y = curPos.y; // current y pos of platform
                             // we calculate the delta
         Vector3 delta = curPos - lastPos;
         float yVelocity = delta.y;
         // remove y component of delta (as we use delta only for correcting
         // horizontal movement now...
         delta.y = 0f;
         lastPos = curPos;
         // let's loop over all characters in the table
         foreach (DictionaryEntry d in onPlatform)
         {
             Data data = (Data)d.Value; // get the data
             float charYVelocity = data.ctrl.velocity.y;
             // check if char seems to be jumping
             if ((charYVelocity & lt;= 0f) || (charYVelocity & lt;= yVelocity)) {
                 // no, lets do our trick!
                 Vector3 pos = data.t.position; // current charactercontroller position
                 pos.y = y + data.yOffset; // adjust to new platform height
                 pos += delta; // adjust to horizontal movement
                 data.t.position = pos; // and write it back!
             }
         }
     }
 
 }

Thank you for any help, much appreciated!

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by doublemax · Jan 18, 2017 at 09:38 PM

Seems like a copy-and-paste problem. Some characters have been converted into their html entities.

 if ((charYVelocity & lt;= 0f) || (charYVelocity & lt;= yVelocity)) {

"& lt;" should be "<"

Comment
Add comment · Show 2 · 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 RonanSmithDev · Jan 18, 2017 at 10:14 PM 1
Share

Thank you, quick and correct solution. Also had to remove the "=" sign too.

avatar image doublemax RonanSmithDev · Jan 18, 2017 at 11:51 PM 0
Share

I'm not so sure about removing the "=" sign. As far as i can tell it makes sense in that place and should stay.

Follow this Question

Answers Answers and Comments

310 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

changing a public variable of a prefab with a script. 0 Answers

error CS8025: Parsing error 1 Answer

Unity Parsing Error CS8025 on Last Line? 2 Answers

Saving and loading an int variable on Android 1 Answer

Unity Math is Wrong for Some Reason 0 Answers


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