This post has been de-listed (Author was flagged for spam)
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
5
(Parallax scrolling) what am I doing wrong here?
Post Flair (click to view more posts with a particular flair)
Post Body
So I'm a little new to C#. I made this script in Javascript that parallaxes individual objects at different speeds. But upon converting to C#, I get the error that I can't convert a double to a float on the last line. I'm not sure what to do beforehand to make this not happen.
public class ParalaxScrolling : MonoBehaviour {
[Tooltip("The speed at which this object scrolls")]
[SerializeField] private float parallaxingSpeed;
//The camera itself
private Transform cam;
//Where the camera was last frame
private Vector3 prevPos;
private Vector3 newPos;
void Awake(){
cam = Camera.main.transform;
}
void Start () {
prevPos = cam.position;
}
void Update () {
//Calculate how much the camera has moved by this frame
float camMovementThisFrame = prevPos.x - cam.position.x;
//Modify speed by different background speeds
float movementInX = camMovementThisFrame * parallaxingSpeed;
//Make MovementInX part of a Vector3, ready for the lerp
newPos = new Vector3(movementInX, this.transform.position.y, this.transform.position.z);
//Smoothly moves between current position and the target position (with a smoothing modifier)
transform.position = Vector3.Lerp(transform.position, newPos, 0.5);
}
}
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 9 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Unity2D/com...