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 24Agree x 5Programming King x 1Funny x 1Zing x 1Informative x 1Artistic x 1 (list)

  3. Post #3
    Stary2001's Avatar
    July 2011
    40 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 5Programming 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
    40 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 4 (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
    40 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 8 (list)

  8. Post #8
    Gold Member
    Eric95's Avatar
    January 2009
    4,789 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?

  9. Post #9
    Gold Member
    Ortzinator's Avatar
    May 2005
    1,647 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 5 (list)

  10. Post #10
    Gold Member
    Darwin226's Avatar
    January 2009
    4,037 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 1 (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 2 (list)

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

  13. Post #13
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,335 Posts
    Why do you?
    For exactly the same reason you did.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Zing Zing x 1 (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 8 (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 4Funny Funny x 1 (list)

  16. Post #16
    Tamschi's Avatar
    December 2009
    2,982 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 5 (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 Dumb Dumb x 1 (list)