Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Struggling with jumping script

Discussion in 'Scripting' started by Danzman4, Oct 30, 2014.

  1. Danzman4

    Danzman4

    Joined:
    Oct 30, 2014
    Posts:
    4
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerMovement : MonoBehaviour {
    5.  
    6.     public float speed = 10f;
    7.     public float jumpSpeed = 6f;
    8.    
    9.     Vector3 direction = Vector3.zero;
    10.     float verticalVelocity = 0f;
    11.  
    12.     CharacterController cc;
    13.  
    14.     // Use this for initialization
    15.     void Start () {
    16.         cc = GetComponent<CharacterController>();
    17.     }
    18.    
    19.     // Update is called once per frame
    20.     void Update () {
    21.  
    22.          direction = transform.rotation * new Vector3( Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical") );
    23.  
    24.                 if(direction.magnitude > 1f) {
    25.                     direction = direction.normalized;
    26.                 }      
    27.  
    28.                 if( Input.GetButton ("Jump")) {
    29.                      Vector3 cc.transform.position.transform.up = jumpSpeed.Time.deltaTime;
    30.                 }
    31.         }
    32.  
    33.             void FixedUpdate () {
    34.  
    35.                Vector3 dist = direction * speed * Time.deltaTime;
    36.  
    37.                verticalVelocity = Physics.gravity.y * Time.deltaTime;
    38.  
    39.                verticalVelocity += Physics.gravity.y * Time.deltaTime;
    40.  
    41.           dist.y = verticalVelocity * Time.deltaTime;
    42.        
    43.           cc.Move( dist );  
    44.       }
    45. }
    46.  
    I have been following some programming and Unity tutorials and have got most of the code from them but the Unity editor keeps complaining with error code CS1525: unexpected symbol '.' expecting ")", ' , ; , [ or =

    I have been trying to fix it for some time now but when I fix it more errors keep coming up with other errors to replace it.

    I would very much appreciate it if you could help me.
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
    The error is on line 29; jumpSpeed is a float, and you can't call Time on it. You probably wanted jumpSpeed * Time.deltaTime.

    UPDATE: That's not the only error on line 29; cc.transform.position doesn't have a transform.
     
    Last edited: Oct 30, 2014
  3. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    There are many errors on line 29 other than that. You need to examine the entirety of it