Let me start by saying that I am a complete beginner, who only got this far by piecing together parts from tutorials and sites like this.
All I am trying to do is make a platform that moves only when stood on.
using UnityEngine;
using System.Collections;
public class MovingPlatform : MonoBehaviour
{
public bool isPlayerOn;
[SerializeField]
Transform platform;
[SerializeField]
Transform startTransform;
[SerializeField]
Transform endTransform;
[SerializeField]
float platformSpeed;
Vector3 direction;
Transform destination;
void OnCollisionEnter (Collision other) {
if (Collision.gameObject.tag == "Player") {
isPlayerOn = true;
}
}
void OnCollisionExit (Collision other) {
if (Collision.gameObject.tag == "Player") {
isPlayerOn = false;
}
}
void Start (){
SetDestination (startTransform);
}
void FixedUpdate(){
platform.rigidbody.MovePosition (platform.position + direction * platformSpeed * Time.fixedDeltaTime);
if (Vector3.Distance (platform.position, destination.position) < platformSpeed * Time.fixedDeltaTime) {
SetDestination (destination == startTransform ? endTransform : startTransform);
}
}
void SetDestination(Transform dest){
destination = dest;
direction = (destination.position -platform.position).normalized;
}
}
Now I have no idea if this will even work, I managed to get rid of about 9 other errors but not this one.
Assets/MovingPlatform.cs(31,31): error CS0120: An object reference is required to access non-static member `UnityEngine.Collision.gameObject'