In-depth game algorithm (4)-unity3d algorithm (3)-Mobile camera

Source: Internet
Author: User

Findwithtag find tag, find lookup name, 2 functions Find game Object

Gameobject.findwithtag

Gameobject.find

The following example moves the camera while tracking the movement of the ball

#pragma strict//code:[email protected]//date:2014-08-13import system;var translate_object:rigidbody;var li:int=20; var floor_y:int;var mycamera:gameobject;var camera_bh:float;function Start () {var floor:gameobject= Gameobject.findwithtag ("Myfloor"); Mycamera=gameobject.find ("Ball_camera"); floor_y=-floor.transform.position.y+ 5;camera_bh=0.01;} function Fixedupdate () {   if (translate_object!=null) {         if (translate_object.rigidbody.transform.position.y <floor_y) {          translate_object.rigidbody.AddForce (0,li,0);              }   }    if (mycamera.transform.rotation.x>-0.10 | | mycamera.transform.rotation.x<-0.12) {       camera_bh=-camera_bh;          }   mycamera.transform.Rotate (camera_bh,0,0);   }

mai good AI Paradise Blog All content is original, if reproduced please indicate source http://blog.csdn.net/myhaspl/

The following layouts:

See the results:

Http://mygame.myhaspl.com/test3/test3.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.