Unity scripts fail

Asked 1 years ago, Updated 1 years ago, 32 views

using UnityEngine;
using System.Collections;

public class ScrollObject:MonoBehavior {
    public float speed = 1.0f;
    public float startPosition;
    public float endPosition;

    void Update() {
        // Move each frame x position little by little
        transform.Translate (-1*speed*Time.deltaTime, 0, 0);
        // Check if the scroll has reached the target point
        if(transform.position.x<=endPosition)ScrollEnd();
    }

    void ScrollEnd() {
        // Return the scrolling distance
        transform.Translate(-1*(endPosition-startPotion), 0, 0);
        // Send messages to components attached to each game object
        SendMessage("onScrollEnd", SendMessageOptions.DontRequireReceiver);
    }
}

Error:

Asset/Script/ScrollObject.cs(21,56): error CS0103: The name `startPotion' does not exist in the current context
Assets/Script/ScrollObject.cs(21,27): error CS1502: The best overloaded method match for `UnityEngine.Transform.Translate(float, float, float)' has some invalid arguments
Assets/Script/ScrollObject.cs(21,27): error CS1503: Argument `#1' cannot convert `object' expression to type `float'

unity3d

2022-09-29 20:29

1 Answers

The startPotion on line 21 of ScrollObject.cs is spelled incorrectly.
If you rewrite startPosition, the error will disappear.

If you do not know how to resolve the error, try the following:

  • Original text: The name `startPotion' does not exist in the current context
  • Translation: The name `startPotion' does not exist in the current context


2022-09-29 20:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.