• Making a moving platform with C# ?
    20 replies, posted
  • Hello, I'm trying to make my moving platform with this code: [CODE]using System.Collections; public class testfloater:MonoBehaviour { public float Speed = 0.2F; public float stopper = 50.0F; public float header = 0.0F; // Use this for initialization void Start () { } // Update is called once per frame void Update () { float moveInput = Time.deltaTime * Speed; transform.position += new Vector3(moveInput, 0, 0); if (transform.position.x = stopper) { float inverseInput = Time.deltaTime * Speed * -1.0F; transform.position += new Vector3(inverseInput, 0, 0); } if (transform.position.x = header) { transform.position += new Vector3(moveInput, 0, 0); } } } [/CODE] But the output say's I cannot modify the return value of "UnityEngine.Transform.position" and that I cannot change a float to a bool. Any suggestions?
  • [code] if (transform.position.x = stopper) [/code] needs to be [code] if (transform.position.x == stopper) [/code] the same with the other if = is assignment, == is comparison.
  • [QUOTE=Stary2001;34541982][code] if (transform.position.x = stopper) [/code] needs to be [code] if (transform.position.x == stopper) [/code] the same with the other if = is assignment, == is comparison.[/QUOTE] Removed the errors, but now the platform doesn't stop, It just keeps going Tried this: [CODE]using UnityEngine; using System.Collections; public class testfloater:MonoBehaviour { public float Speed = 0.2F; public float stopper = 50.0F; public float header = 0.0F; // Use this for initialization void Start () { } // Update is called once per frame void Update () { float moveInput = Time.deltaTime * Speed; transform.position += new Vector3(moveInput, 0, 0); if (transform.position.x == stopper) { moveInput = moveInput * -1.0F; transform.position += new Vector3(moveInput, 0, 0); } if (transform.position.x == header) { moveInput = moveInput * -1.0F; transform.position += new Vector3(moveInput, 0, 0); } } } [/CODE] Still having the same problem.
  • I think this might work better for Update() [code] void Update () { transform.position += new Vector3(Time.deltaTime * Speed, 0, 0); // apply movement if ((transform.position.x > stopper) ||(transform.position.x < header)) // if we are past either of these then { transform.position -= new Vector3(Time.deltaTime * Speed, 0, 0); // undo the move Speed=-Speed; // go the other way by negating speed } } [/code] tested it in unity just now and it works!
  • [QUOTE=Stary2001;34542761]I think this might work better for Update() [code] void Update () { transform.position += new Vector3(Time.deltaTime * Speed, 0, 0); // apply movement if ((transform.position.x > stopper) ||(transform.position.x < header)) // if we are past either of these then { transform.position -= new Vector3(Time.deltaTime * Speed, 0, 0); // undo the move Speed=-Speed; // go the other way by negating speed } } [/code] tested it in unity just now and it works![/QUOTE] Awesome dude thanks!
  • I usually use Javascript in Unity, I've tried some C# and I can't really find any differences except for slightly different syntax and a function being called a void. Are there any huge differences?
  • [QUOTE=Eric95;34547324]I usually use Javascript in Unity, I've tried some C# and I can't really find any differences except for slightly different syntax and a function being called a void. Are there any huge differences?[/QUOTE] Static typing alone makes it worth switching IMO.
  • [QUOTE=Eric95;34547324]I usually use Javascript in Unity, I've tried some C# and I can't really find any differences except for slightly different syntax and a function being called a void. Are there any huge differences?[/QUOTE] Void just means the function returns nothing. If it returned a number for example it would say int, double or float.
  • [QUOTE=AtomiCasd;34541925]Your code looks so ugly a paper bag wouldn't even help.[/QUOTE] Why even bother commenting?
  • [QUOTE=BrutalSnyper;34558346]Why even bother commenting?[/QUOTE] Why do you?
  • [QUOTE=AtomiCasd;34541925]Your code looks so ugly a paper bag wouldn't even help.[/QUOTE] Says the guy who's profile picture is a guy wearing a gas mask? He must be pretty ugly.
  • Hey guys. Can some1 help me plz. I'm trying to learn how & write a script for a plateform game from a youtube tut from 3DBuzz. The script that he is using looks like this but I keep getting different results. using System using System.Collections.Generic; using UnityEngine; using System.Collections; public class PathDefinition : MonoBehaviour) { public Transform[] Points; { public IEnumerator<Transform> GetPathsEnumerator() { throw new NotImplementedException(); { public void OnDrawGizmo() { if (Points.Length < 2) return; for (SerializePrivateVariables i = 1; i <Points.Length; i++) { Gizmos.DrawLine(Points[i - 1].position, points i.Position
  • [QUOTE=onya76;45304669]Hey guys. Can some1 help me plz. I'm trying to learn how & write a script for a plateform game from a youtube tut from 3DBuzz. The script that he is using looks like this but I keep getting different results. using System using System.Collections.Generic; using UnityEngine; using System.Collections; public class PathDefinition : MonoBehaviour) { public Transform[] Points; { public IEnumerator<Transform> GetPathsEnumerator() { throw new NotImplementedException(); { public void OnDrawGizmo() { if (Points.Length < 2) return; for (SerializePrivateVariables i = 1; i <Points.Length; i++) { Gizmos.DrawLine(Points[i - 1].position, points i.Position[/QUOTE] 1. Please use English, your sentence is hard to read. 2. Please use [noparse][code][/code][/noparse] tags, your code is hard to read. 3. Please give descriptions of the expected and actual result, it's hard to know what you want just from the channel name. 4. It seems half of your code is missing, this shouldn't even compile.
  • Here is the link of the video tutorial that I am trying to follow. [url]https://www.youtube.com/watch?v=ZkGPoZOQE5Q[/url] Just watch about the first 9 and a half minutes of the video & you will see what I'm talking about.... I'm working on a 2D platform game almost like Super Mario Bro's..... & I get his coding 100% matched to mine then I get errors. He is trying to draw lines from point A to Point B to Point C for the platform. & when he loads his. under script up by the add component, he has point to point the new game object to the script. & on mine it just shows script. And thank for your help & sorry for the bad description in the earlier post.....
  • Ok. Finally figured it out. Thanks for your help & once again, I'm sorry about my poor definitions & explainning things. But anyways. Thanks.....
  • [QUOTE=onya76;45313198]Ok. Finally figured it out. Thanks for your help & once again, I'm sorry about my poor definitions & explainning things. But anyways. Thanks.....[/QUOTE] Hi. I have the same problem. Could you please explane how does it works? I mean this script. I used this script but didn't see the folder "Points" in my Inspector under the script. Sorry about my english. I'm from Ukraine and don't speack english fluently.
  • If you want to do platforms, attach the element to the plataform, so the plataform translate the position to the children objects (And don't bump 2yo threads)
  • [QUOTE=Eric95;34547324]I usually use Javascript in Unity, I've tried some C# and I can't really find any differences except for slightly different syntax and a function being called a void. Are there any huge differences?[/QUOTE] Late but C# is an incredibly rich language with a lot of features that makes code more maintainable, easier and faster to write. It's definitely worth learning if you are a programming type otherwise I wouldn't bother, most professional studios that use Unity use C# although Javascript is still a fine choice.