using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public GameObject Player;
public Rigidbody PlayerRB;
public bool IsGrounded;
public float JumpPower;
public float Gravity;
public float PlayerY;
public float speed;
public float Y;
void Start ()
{
PlayerRB = Player.GetComponent<Rigidbody> ();
}
void Update ()
{
Player.transform.position.y = Y;
Player.transform.Translate (-Vector3.left * speed * Time.deltaTime);
Player.transform.rotation = (Quaternion.identity);
IsOnGround();
GravityCheck ();
Jump ();
}
void Jump()
{
if (Input.GetKeyDown (KeyCode.Space) && IsGrounded == true)
{
PlayerRB.AddForce(transform.up * JumpPower);
}
}
void IsOnGround()
{
RaycastHit hitInfo;
int layerMask = ~(1 << LayerMask.NameToLayer("Player"));
float distance = 0.8f;
if (Physics.Raycast (transform.position, Vector3.down, out hitInfo, distance, layerMask))
{
IsGrounded = true;
} else
{
IsGrounded = false;
}
}
void GravityCheck()
{
if (IsGrounded != true)
{
Y = PlayerY - Gravity;
}
}
}
ERROR:
Assets/Scripts/PlayerController.cs(25,34): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable