How do i get my cloud to move up and down automatically based on a delay of a few seconds?
(I’d like to use C#, not javascript or boo)
So on your cloud object, create a new C# script called “BounceObject” and add this code below in
using UnityEngine;
using System.Collections;
public class BounceObject : MonoBehaviour
{
public bool Move = true; ///gives you control in inspector to trigger it or not
public Vector3 MoveVector = Vector3.up; //unity already supplies us with a readonly vector representing up and we are just chaching that into MoveVector
public float MoveRange = 2.0f; //change this to increase/decrease the distance between the highest and lowest points of the bounce
public float MoveSpeed = 0.5f; //change this to make it faster or slower
private BounceObject bounceObject; //for caching this transform
Vector3 startPosition; //used to cache the start position of the transform
void Start()
{
bounceObject = this;
startPosition = bounceObject.transform.position;
}
void Update()
{
if(Move) //bool is checked
//See if you can work out whats going on here, for your own enjoyment
bounceObject.transform.position = startPosition + MoveVector * (MoveRange * Mathf.Sin(Time.timeSinceLevelLoad * MoveSpeed));
}
}
Tested Working in Unity 4.3.2 f1 on 08/03/2014
So …I hope that helps you bud…
If so, please mark it as an Answer so that others who come across the same problems may also find this solution to help them out too.
Gruffy