Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by $$anonymous$$ · Oct 12, 2015 at 12:45 PM · playerscript.enemyaienemy spawncant

I have problems with Enemy and Player scripts.

4 part question. Yes I am new to all this. No I am not asking someone to build the whole thing for me. And I do have learning disabilities so i need each line where corrections can be made specified. Note that I'm using Unity 5.2.1.

1:

How do i stop enemy target blowing up on contact with terrain, because it also destroys terrain. script:

 using UnityEngine;
 using System.Collections;
 
 public class DestroyByContact : MonoBehaviour
 {
     public GameObject explosion;
     public GameObject playerExplosion;
     public int scoreValue;

 void Start()
 {
 }

 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Boundary")
     {
         return;
     }
     Instantiate(explosion, transform.position, transform.rotation);
     if (other.tag == "Player")
     {
         Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
     }

     Destroy(other.gameObject);
     Destroy(gameObject);
 }

}

2:

Enemies are not spawning in different spawn locations with the spawn points already placed where they should. They spawn at the same point. I try and remove parts of this script and i get errors in visual studio. When they do spawn its under the terrain.

script.

 public class EnemySpawner : MonoBehaviour {
     public GameObject hazard;
     public Vector3 spawnValues;
     public float spawnTime = 4f;
     public Transform[] spawnPoints;
     public float waveWait;
     public object spawn
     {
         get; private set;
     }
     void Start()
     {
         InvokeRepeating("Spawn", spawnTime, spawnTime);
     }
     void Spawn()
     {
         Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
         Quaternion spawnRotation = Quaternion.identity;
         Instantiate(hazard, spawnPosition, spawnRotation); Instantiate(hazard, spawnPosition, spawnRotation);
     }
 }

  1. My character for player is a flying character. The Enemy AI_Follow causes the enemies to float up off the ground even with rigid body check for using gravity and kinematics, and fix to the Y and X,Y,Z axes.

As an extra note my playing character also has a rigid body and collider but still passes through the ground.

Side note:

haven't been abler to figure out how to apply health properly to enemies or character which obviously i need in place before attempting to script a Game Controller or GUI.

The four Player Scripts are as follows;

                     The first two are for the shooting. 

Movement for Bullet (has a destroy its clone option):

 using UnityEngine;
 using System.Collections;
 
 public class Mover : MonoBehaviour
 {
     public float speed =10.0f;
     
     void Start ()
     {
         GetComponent<Rigidbody>().velocity = transform.forward * speed;
         Destroy(this.gameObject, 6);
    }
 }
 

Shoot Script (where the bullet comes out):

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class Shoot : MonoBehaviour
 {
     public GameObject bullet;
     public float delayTime = 1;
 
     private float counter = 0;
 
     void Start()
     {
     }
 
     void Update()
     {
 
         if (Input.GetKey(KeyCode.Mouse0) && counter > delayTime)
         {
             Instantiate(bullet, transform.position, transform.rotation);
             GetComponent<AudioSource>().Play();
             counter = 0;
         }
         counter += Time.deltaTime;
     }
 
     internal static void DisableEffects()
     {
         throw new NotImplementedException();
     }
 }

(I know how to add to have two different types of enemies in this script, but its pointless if they spawn in the same location and blow each other and the terrain up.

                 The second two are player movement

Allows me to look and move in that direction.

     using UnityEngine;
     using System.Collections;

     public class MouseLook : MonoBehaviour {
     public float LookSensitivity = 0.0f;
     public float xRotation;
     public float yRotation;
     public float currentXRotation;
     public float currentYRotation;
     public float xRotationV;
     public float yRotationV;
     public float lookSmoothDamp = 0.0f;

     // Use this for initialization
     void Start()
     {
     }

     // Update is called once per frame
     void Update()
     {
         yRotation += (Input.GetAxis("Mouse X") * LookSensitivity);
         xRotation -= (Input.GetAxis("Mouse Y") * LookSensitivity);

         xRotation = Mathf.Clamp(xRotation, -90, 90);

         currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
         currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
         transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
     }
 }

Basic movement Forward; Backward and Side to side but still facing on the Z axis hence the reason for using the mouse look. (PS changing these codes throw me constant errors)

 using UnityEngine;
 public class PlayerMovement : MonoBehaviour {
     public float moveSpeed = 45.0f;

     // Use this for initialization
     void Start()
     {
     }

     // Update is called once per frame
     void Update()
     {
         transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
    }
 }

So at this point i'm really stuck and i haven't seen any tutorial videos that help with C# specific Unity 5+ and many of the references i have searched through are badly out of date.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Oct 12, 2015 at 03:26 AM 0
Share

sorry the second script is smooshed. I'll try again.

using UnityEngine; using System.Collections;

public class EnemySpawner : $$anonymous$$onoBehaviour {

 public GameObject hazard;
 public Vector3 spawnValues;
 public float spawnTime = 4f;
 public Transform[] spawnPoints;
 public float waveWait;
 public object spawn
 {
     get; private set;
 }
 void Start()
 {
     InvokeRepeating("Spawn", spawnTime, spawnTime);
 }
 void Spawn()
 {
     Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
     Quaternion spawnRotation = Quaternion.identity;
     Instantiate(hazard, spawnPosition, spawnRotation); Instantiate(hazard, spawnPosition, spawnRotation);
 }

}

avatar image $$anonymous$$ · Oct 12, 2015 at 03:30 AM 0
Share

Ill be back because im trying to figure out how to get the enemy snowman to shoot back

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

31 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't move my player in a fps? 1 Answer

I have 2 enemies connected to one script but when one enemy dies using destroy(gameObject); the other enemy is still present but my character doesn't recognize it as an enemy 0 Answers

Transfering script to other game objects via code (Unity 2D) 0 Answers

How to make all enemies attack after spawning? Not only 1. 1 Answer

How to organise game data for multiplayer with a player manager? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges