1. Post #1

    August 2011
    74 Posts
    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);
    		}
    		
    	
    }
    }
    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?

  2. Post #2
    AtomiCasd's Avatar
    June 2011
    588 Posts
    Your code looks so ugly a paper bag wouldn't even help.
    Reply With Quote Edit / Delete Reply Windows 7 Norway Show Events Dumb x 37Agree x 5Funny x 3Disagree x 2Zing x 2Informative x 1Artistic x 1Programming King x 1 (list)

  3. Post #3
    Stary2001's Avatar
    July 2011
    41 Posts
    Code:
    if (transform.position.x = stopper)
    needs to be

    Code:
    if (transform.position.x == stopper)
    the same with the other if

    = is assignment, == is comparison.
    Reply With Quote Edit / Delete Reply Windows Vista United Kingdom Show Events Agree Agree x 7Programming King Programming King x 2Useful Useful x 1 (list)

  4. Post #4

    August 2011
    74 Posts
    Code:
    if (transform.position.x = stopper)
    needs to be

    Code:
    if (transform.position.x == stopper)
    the same with the other if

    = is assignment, == is comparison.
    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);
    		}
    		
    	
    }
    }
    Still having the same problem.

  5. Post #5
    Stary2001's Avatar
    July 2011
    41 Posts
    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
    	}
    }
    tested it in unity just now and it works!
    Reply With Quote Edit / Delete Reply Windows Vista United Kingdom Show Events Programming King Programming King x 6 (list)

  6. Post #6

    August 2011
    74 Posts
    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
    	}
    }
    tested it in unity just now and it works!
    Awesome dude thanks!

  7. Post #7
    Stary2001's Avatar
    July 2011
    41 Posts
    If you have any other problems, you can PM me and I'll help.
    Reply With Quote Edit / Delete Reply Windows Vista United Kingdom Show Events Friendly Friendly x 11 (list)

  8. Post #8
    Gold Member
    Eric95's Avatar
    January 2009
    5,046 Posts
    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?
    Reply With Quote Edit / Delete Reply Windows 7 Sweden Show Events Dumb Dumb x 1 (list)

  9. Post #9
    Gold Member
    Ortzinator's Avatar
    May 2005
    1,648 Posts
    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?
    Static typing alone makes it worth switching IMO.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 8Disagree Disagree x 1 (list)

  10. Post #10
    Gold Member
    Darwin226's Avatar
    January 2009
    4,158 Posts
    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?
    Void just means the function returns nothing.
    If it returned a number for example it would say int, double or float.
    Reply With Quote Edit / Delete Reply Windows 7 Croatia Show Events Agree Agree x 4 (list)

  11. Post #11

    October 2011
    35 Posts
    Your code looks so ugly a paper bag wouldn't even help.
    Why even bother commenting?
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Agree Agree x 4Dumb Dumb x 1 (list)

  12. Post #12
    Gold Member
    Nisd's Avatar
    October 2008
    436 Posts
    Why even bother commenting?
    Why do you?
    Reply With Quote Edit / Delete Reply Windows 7 Denmark Show Events Dumb Dumb x 13Funny Funny x 1 (list)

  13. Post #13
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,562 Posts
    Why do you?
    For exactly the same reason you did.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb Dumb x 3 (list)

  14. Post #14
    IndieGamer's Avatar
    February 2012
    65 Posts
    Your code looks so ugly a paper bag wouldn't even help.
    Says the guy who's profile picture is a guy wearing a gas mask? He must be pretty ugly.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb Dumb x 13Funny Funny x 1Disagree Disagree x 1Late Late x 1 (list)

  15. Post #15

    July 2014
    3 Posts
    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
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Dumb Dumb x 7Disagree Disagree x 1Funny Funny x 1 (list)

  16. Post #16
    Tamschi's Avatar
    December 2009
    3,615 Posts
    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
    1. Please use English, your sentence is hard to read.
    2. Please use [code][/code] 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.
    Reply With Quote Edit / Delete Reply Windows 7 Germany Show Events Agree Agree x 6 (list)

  17. Post #17

    July 2014
    3 Posts
    Here is the link of the video tutorial that I am trying to follow. https://www.youtube.com/watch?v=ZkGPoZOQE5Q 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.....
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Funny Funny x 1 (list)

  18. Post #18

    July 2014
    3 Posts
    Ok. Finally figured it out. Thanks for your help & once again, I'm sorry about my poor definitions & explainning things. But anyways. Thanks.....
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Friendly Friendly x 2Dumb Dumb x 1 (list)

  19. Post #19

    October 2014
    1 Posts
    Ok. Finally figured it out. Thanks for your help & once again, I'm sorry about my poor definitions & explainning things. But anyways. Thanks.....
    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.
    Reply With Quote Edit / Delete Reply Ukraine Show Events Dumb Dumb x 2Funny Funny x 1 (list)

  20. Post #20
    Can someone give me a dayz copy?
    gonzalolog's Avatar
    April 2011
    1,371 Posts
    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)

  21. Post #21
    Hi.
    reevezy67's Avatar
    July 2011
    4,406 Posts
    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?
    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.
    Reply With Quote Edit / Delete Reply Windows 8 Australia Show Events Agree Agree x 2 (list)