Hi, I am trying to make a game based on the apple picker prototype mentioned
in the book introduction to Introduction to Game Design, Prototyping, and Development. But changed apple tree to snowman and snowballs.
/The /basic movement part works but when I add the //changing direction part of the script I get errors.
Help appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SnowController : MonoBehaviour
{
public GameObject SnowballPrefab;
public float speed = 1f;
public float leftAndRightEdge = 10f;
public float chanceToChangeDirections = 0.1f;
public float secondsBetweenSnowballDrops = 1f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//basic movement
Vector3 pos = transform.position;
pos.x += speed * Time.deltaTime;
transform.position = pos;
// Changing Direction
if (pos.x < -leftAndRightEdge) // move right
{
speed = Mathf.Abs(speed);
}
else if (pos.x > leftAndRightEdge) // move left
{
speed = -Mathf.Abs(speed);
}
}