Jump to content
Unity Insider Forum

Auto-Zielen eines Turret Towers


docdum

Recommended Posts

Moin zusammen,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/*
	acs_base_main.cs
*/

public class acs_gun : MonoBehaviour {

	[Header("Basic Values")]
	private Rigidbody _RB;
	public float _SPEED = 15f;
	public float _RotSpeed = .9f;
	private float _shotCounter;
	private float _shotCMax = 10f;
	private Quaternion _rotationAngle;

	[Header("Components")]
	public GameObject _acsBase;
	public GameObject _gun;
	private acs_base_main _acsScript;
	public GameObject _gunfire;

	[Header("Extern")]
	public GameObject _OWNEXPLO;
	private GameObject _Player;

	// Use this for initialization
	void Start () {
		_RB = gameObject.GetComponent<Rigidbody>();
		_Player = GameObject.Find ("Player");
		_acsScript = _acsBase.GetComponent<acs_base_main> ();
	}

	// Update is called once per frame
	void Update () {

		_shotCounter += .1f;

		//look to the player
		_rotationAngle = Quaternion.LookRotation (_Player.transform.position);
		_rotationAngle.x = 0f;
		_rotationAngle.z = 0f;
		transform.rotation = Quaternion.Slerp (transform.rotation, _rotationAngle, _RotSpeed * Time.deltaTime) ;

		if (_shotCounter >= _shotCMax/* and rotation is done*/) {
			Debug.Log ("ACE gun shot");
			_shotCounter = 0f;
		}

		if (_acsScript._isAlive == false) {
			GameObject.Instantiate(_OWNEXPLO, gameObject.transform.position, gameObject.transform.rotation);
			Destroy(gameObject, 3f);
		}
	}
}

Ich habe jetzt folgendes Skript erstellt, um den Tower eines Turrets um die y-Achse zu drehen und sich zum Spieler auszurichten. aber es funktioniert nicht richtig. auf der X Achse.

Link zu diesem Kommentar
Auf anderen Seiten teilen

Archiviert

Dieses Thema ist jetzt archiviert und für weitere Antworten gesperrt.

×
×
  • Neu erstellen...