Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

FPS Bullet Script

Discussion in 'Scripting' started by ARAKIT, Jan 10, 2018.

  1. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    Hello,

    I am making an FPS shooter game, with a little sphere named Bullet. I want Bullet to go to the current position of the character which is named char_shadow. I tried using this script but it would not work.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class scriptforsphere : MonoBehaviour {
    6.  
    7.     GameObject char_shadow;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.        
    12.     }
    13.    
    14.     float speed;
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.         float step = speed * Time.deltaTime;
    19.         transform.position = Vector3.MoveTowards(transform.position, char_shadow.transform.position, step);
    20.     }
    21. }
     
  2. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    Please Help!
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,710
    try changing 'float speed' to 'public float speed' and setting a value greater than 0 from the inspector. :)
     
  4. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    helps, but still doesn't work
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,710
    Helps? :) before it would have been zero, so never move.
    What is happening? Explain more beyond it doesn't work, please.

    Do you have any errors?
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,116
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,710
    ah, so it is :)
     
  8. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    ok, I got it to work, i just needed to make it public
     
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,710
    Cool, glad you got it working.