Search Unity

invalid parameter type 'void'

Discussion in 'Getting Started' started by louisonag, Feb 8, 2019.

  1. louisonag

    louisonag

    Joined:
    Feb 8, 2019
    Posts:
    4
    Hello, it remains only one error in my script which is the type of "CharacterController" for a variable.
    Can someone help me ?:)




    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     private var distance;
    8.     private Transform target;
    9.     private int lookAtDistance = 20;
    10.     private int chaseRange = 10;
    11.     private float attackRange = 2.2f;
    12.     private int moveSpeed = 3;
    13.     private int damping = 6;
    14.     private int attackRepeatTime = 1;
    15.     private int theDammage = 15;
    16.     private float attackTime = 3;
    17.     public var controller(void CharacterController);
    18.     private float gravity = 20;
    19.     private void moveDirection(string Vector3 = Vector3.zero);
    20.     private Animator zombieAnim;
    21.     private float vert;
    22.  
    23.  
    24.  
    25.     // Start is called before the first frame update
    26.     void Start()
    27.     {
    28.         attackTime = attackTime.time;
    29.         FindHealth();
    30.     }
    31.  
    32.     // Update is called once per frame
    33.     void Update()
    34.     {
    35.         distance = Vector3.Distance(Target.position, transform.position);
    36.  
    37.         if (distance < lookAtDistance)
    38.         {
    39.             lookAt();
    40.         }
    41.         if (distance < attackRange)
    42.         {
    43.             attack();
    44.         }
    45.  
    46.         else if(distance < chaseRange){
    47.             chase();
    48.         }
    49.     }
    50.  
    51.     void lookAt()
    52.     {
    53.         var rotation = Quaternion.LookRotation(target.position - transform.position);
    54.         transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Dampling);
    55.     }
    56.  
    57.     void chase()
    58.     {
    59.         GetComponent.Animator.Play("walk");
    60.         moveDirection = transform.forward;
    61.         moveDirection *= moveSpeed;
    62.         moveDirection.y -= gravity * attackTime.deltaTime;
    63.         controller.Move(moveDirection * Time.deltaTime);
    64.     }
    65.  
    66.     void attack()
    67.     {
    68.         if(attackTime.time > attackTime)
    69.         {
    70.             GetComponent.Animator.Play("attack");
    71.             target.SendMessage("ApplyDamage", theDammage);
    72.             print("ennemy attacks");
    73.             attackTime = attackTime.time + attackRepeatTime;
    74.         }
    75.     }
    76.  
    77.     void applyDammage()
    78.     {
    79.         chaseRange += 30;
    80.         moveSpeed += 2;
    81.         lookAtDistance += 40;
    82.     }
    83.  
    84.     void findHealth()
    85.     {
    86.         target = GameObject.Find("PlayerStats").GetComponent(PlayerStats).transform;
    87.     }
    88. }
    89.  
     
  2. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    328
    what does this mean? are you sure it's c# code?
    it looks like you randomly typed some keywords and brackets... :D

    I suppose it's meant to be
    Code (csharp):
    1.  
    2. public CharacterController controller;
    3. Vector3 moveDirection;
    4.  
     
  3. louisonag

    louisonag

    Joined:
    Feb 8, 2019
    Posts:
    4
    Thanks, I'm going to try :)
    Yes I follow a tutorial in java Script and I try to translate (as I can because I'm a beginner)
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I'm sure others will also recommend not to use tutorials that require a beginner to translate, it will slow you down and likely just cause frustration. There are plenty of C#/Unity tutorials!
     
  5. louisonag

    louisonag

    Joined:
    Feb 8, 2019
    Posts:
    4
    It works !
    thanks a lot ! And now I have another problems which I must resolve too :mad::D
     
  6. louisonag

    louisonag

    Joined:
    Feb 8, 2019
    Posts:
    4
    of course but I had to follow this ones
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Why